> ## Documentation Index
> Fetch the complete documentation index at: https://docs.generalvalidation.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Run validation from code

> Prepare Runs through the API, start the validation pipeline in Fabric from a script or agent, poll for verdicts, and dynamically validate multiple sources with a test set.

A script, CI/CD job, or agent can prepare a Run through the General Validation
API, start the validation pipeline in your Microsoft Fabric workspace, and poll
for each Test's verdict and counts.

> [!TIP]
>
> To trigger validation directly from a Microsoft Fabric Data Pipeline without
> writing REST calls, follow
> [Run validation from your Fabric pipeline](https://docs.generalvalidation.com/validate-data/run-from-a-pipeline.md).

## Before you start

* An Owner has activated the Organization and set up the Environment in the
  app.
* Your tool calls the General Validation API with a workload identity that has
  `GV.APIContributor`; see [API authentication](https://docs.generalvalidation.com/api/authentication.md).
* Your tool starts the pipeline in Fabric with an identity that has
  **Contributor**, **Member**, or **Admin** on the dedicated General Validation
  workspace. A service principal also needs your Fabric administrator to enable
  **Service principals can call Fabric public APIs**.
* Your Environment's workspace identity has read access to the source and
  target Tables; see
  [Give the workspace identity read access](https://docs.generalvalidation.com/api/author-tests.md#give-the-workspace-identity-read-access).

## Start a Run for an existing Table Pair

1. Prepare the Run with `POST /api/v1/fabric/runs` and a new Run ID:
   `{"id": "<new-uuid>", "pair_id": "<pair-id>"}`, or identify the pair by its
   Tables as the [next section](#validate-each-source-a-pipeline-loads)
   describes. The response returns `payload_base64` and `report.token`; treat
   the token as a secret and keep it out of logs. If the call times out, resend
   it with the same Run ID: the response returns the Run and `payload_base64`
   without the token, and
   `POST /api/v1/fabric/runs/<run-id>:regenerate-report-token` issues a new
   token until the Run's job is recorded.

2. Read `workspace_id` and `pipeline_id` from `GET /api/v1/fabric/settings`.

3. Start the validation pipeline in Fabric with your Fabric token:

   ```bash theme={null}
   curl --fail-with-body --include \
     --header "Authorization: Bearer ${fabric_access_token}" \
     --header "Content-Type: application/json" \
     --data '{"executionData": {"parameters": {"mode": "run", "payload_base64": "<payload_base64>", "run_id": "<run-id>", "report_token": "<report.token>"}}}' \
     "https://api.fabric.microsoft.com/v1/workspaces/<workspace_id>/items/<pipeline_id>/jobs/instances?jobType=Pipeline"
   ```

4. Record the Fabric job ID—the last segment of the `Location` header in
   Fabric's response—by calling `POST /api/v1/fabric/runs/<run-id>/submission`
   with `{"job_id": "<job-id>"}`. The app then shows the Run as submitted and
   links it to Fabric Monitor.

5. Poll `GET /api/v1/fabric/runs/<run-id>` until `status` is `passed`,
   `failed`, or `error`, and inspect each Test's Result in the response. Treat
   both `failed` and `error` as unsuccessful outcomes in release or pipeline
   gates.

A Run counts toward your plan only when it returns a verdict (`passed` or
`failed`). Preparing a Run returns `402` with
[`billing.free_runs_used`](https://docs.generalvalidation.com/errors/billing.free_runs_used) when free Runs are
used and no subscription is active, and with
[`billing.run_limit_reached`](https://docs.generalvalidation.com/errors/billing.run_limit_reached) at the monthly
limit. `GET /api/v1/billing/entitlement` shows how the next Run would be
charged in `nextRun`, or why it would be blocked in `nextRunRefusal`. See
[Plans and pricing](https://docs.generalvalidation.com/administration/plans.md).

Exact values and mismatch evidence stay in your Results Lakehouse. Open the Run
in the app and select **View details** to inspect them with your own Fabric
access.

## Validate each source a pipeline loads

A pipeline or orchestrator that loads many sources can validate each one as its
own Table Pair, reusing Tests written once in a test set. Instead of `pair_id`,
each `POST /api/v1/fabric/runs` call names the source and target Tables it just
loaded, their filters, and the test set. The first call for those Tables and
filters creates the Table Pair, and subsequent calls find it, so each source
keeps one Table Pair with its own Run history. On a test set's page in the app,
**Run from your pipeline** shows this payload with the set's ID filled in.

```json theme={null}
{
  "id": "<new-uuid>",
  "source": {
    "workspace_id": "<source-workspace-id>",
    "lakehouse_id": "<source-lakehouse-id>",
    "path": "Tables/<schema>/<source-table>",
    "format": "delta"
  },
  "target": {
    "workspace_id": "<target-workspace-id>",
    "lakehouse_id": "<target-lakehouse-id>",
    "path": "Tables/<schema>/<target-table>",
    "format": "delta"
  },
  "target_filters": [
    {"column": "<column>", "operator": "=", "value": "<value>"}
  ],
  "name": "<Table Pair name>",
  "test_set_id": "<test-set-id>"
}
```

Each side accepts a Lakehouse, Warehouse, or SQL database table in the same
shape as `POST /api/v1/fabric/pairs`; see **Endpoints** in the sidebar for each
schema. `source_filters` and `target_filters` accept the filters a Table Pair
saves; omit either for none.

* **Matching rule:** The Tables and filters determine which Table Pair the call
  uses. The call matches the single active Table Pair comparing the same Tables
  with the same filters (in any order). Send the exact same Tables and filters
  for a source each time, because a different filter value creates or selects a
  different Table Pair.
* **Naming and test set:** `name` and `test_set_id` apply only when the call
  creates the Table Pair. Without `name`, the new pair is named for its Tables
  and filters: `<source> to <target>`, with `where` and the filters after each
  side that has them (for example
  `crm_de.accounts to silver.accounts where source_system = "crm_de"`). A name
  exceeding 255 characters omits the filters. An existing pair matched by the
  call keeps its own name and Tests, and you can rename any pair in the app.
* **Default Table names:** A Lakehouse or Warehouse Table saved without a
  `name` is named `schema.table`, matching SQL database tables. In a Lakehouse
  without schemas, it uses the table name alone.
* **Missing test set:** When no Table Pair matches and the call omits
  `test_set_id`, the API returns `422` with
  [`request.invalid`](https://docs.generalvalidation.com/errors/request.invalid).
* **Ambiguous match:** When more than one active Table Pair matches, the API
  returns `409` with [`fabric.conflict`](https://docs.generalvalidation.com/errors/fabric.conflict). Pass
  `pair_id` instead.

The response's `pair_id` identifies the Table Pair the Run uses. Start the Run
in Fabric the same way as described in
[Start a Run for an existing Table Pair](#start-a-run-for-an-existing-table-pair).

Sources that load into one shared target stay separated by a fixed filter on
each pair—for example, `region = North` on the North pair's target filter. A
filter is always a fixed value saved with its Table Pair.

Because the first call creates the Table Pair and prepares its Run immediately,
grant the workspace identity read access to the Tables beforehand: Viewer on
each workspace, and for a Lakehouse, Read on the Tables' paths in a OneLake
data access role (see
[Give the workspace identity read access](https://docs.generalvalidation.com/api/author-tests.md#give-the-workspace-identity-read-access)).
Once the pair exists, `GET /api/v1/fabric/pairs/<pair-id>/read-access` reports
any remaining access needed, and a Run without access ends with **Could not
read a Table**.

In the app, a Table Pair created this way behaves like any other Table Pair: it
uses the test set, **Run validation** and **Run all** run it, and **Make
independent** gives it its own copy of the Tests.

## Related content

* [Author Table Pairs and Tests](https://docs.generalvalidation.com/api/author-tests.md)
* [Run validation from your Fabric pipeline](https://docs.generalvalidation.com/validate-data/run-from-a-pipeline.md)
* [API authentication](https://docs.generalvalidation.com/api/authentication.md)
* [Error codes](https://docs.generalvalidation.com/administration/errors.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.