# Validate your code

validate_code checks code your AI wrote against the real Provenance API before you run it, and names the line, the rule and the fix for each finding.

`validate_code` is a tool on the [docs MCP](https://provenanceauth.com/docs/provenance-mcp/docs-mcp.md), and among the [developer tools](https://provenanceauth.com/docs/provenance-mcp/developer-tools.md) on Provenance MCP. Your AI writes code, then asks the tool to check it against the public API before you run it. Each finding names the file, line and column, the rule, a message, the fix and a link to the rule below.

## What it takes

| Input | What it is |
| --- | --- |
| `files` | 1 to 20 files, each `{ path, content }`, at most 200,000 characters in all. Or send `code`, one snippet. |
| `language` | `typescript`, `javascript`, `python`, `go` or `shell` (curl counts as shell). Any other language gets only `secret_in_code` and `unknown_operation`. |
| `framework` | Optionally `next`, `express`, `fastapi`, `django` or `none`. |
| `environment_intent` | `sandbox` (the default) or `live`: where the code is meant to run. |

The path only helps the rules: a file with `"use client"`, or under `components/` or `public/`, is browser code. Nothing is read from disk.

## What it answers

| Field | What it is |
| --- | --- |
| `findings` | Each finding: `rule`, `severity` (`error`, `warning` or `info`), `file`, `line`, `column`, `excerpt` (up to 120 characters of your own line), `message`, `fix`, `docs_url` and `operation_id` when an operation applies. Errors come first. |
| `summary` | The count of each severity. |
| `checked` | The rules that ran. |
| `skipped` | Each rule and reason it skipped something: a body built in code, a language the rule doesn't cover. |
| `note` | Always: "Static checks only. Run it in sandbox and use check_integration to see real requests." |

With no findings it answers "No problems found by these checks". It never says your integration is correct.

## Limits

The checks match patterns in the text. They can flag code that is fine and miss code that isn't. A path or body built in another function or file, or by a generated client, is skipped and listed in `skipped`. Nothing is run, installed, imported or fetched. Run your code against the sandbox and use `check_integration` to see the real requests.

## Privacy

The code you send is never stored, logged or sent anywhere. The docs server keeps no request bodies. The developer server's request log records the call with your code replaced by the file count and size, and its answer withheld. Metrics count rule names only.

## Rules

### `unknown_operation`

Error. A literal `/v1/…` path or an SDK method that matches no operation in the public API. A route that exists outside the public API (a console route) is a warning: it can change without notice. Use [api_search](https://provenanceauth.com/docs/provenance-mcp/docs-mcp.md#tools) to find the operation you meant.

### `wrong_method`

Error. A known path called with a method the API doesn't define for it, such as `PUT` where it takes `PATCH`.

### `unknown_field`

Error. A key in a request body written out next to a recognised call that isn't in the operation's request schema, with the nearest valid name ("did you mean…?").

### `missing_required_field`

Warning. A request body written out without a field the schema requires. Skipped when the body is built in code.

### `unknown_response_field`

Warning. A property read on an SDK call's result that the response doesn't have.

### `hash_binding_missing`

Error. An intent token verified (`POST /v1/authorize/verifications`, `POST /v1/mandate/assessments`) without the action it was approved for, or an order hash computed by hand instead of by the SDK.

### `secret_in_code`

Error. An API key or webhook secret written in the code instead of read from an environment variable. A published sandbox key from these docs is a note, not an error.

### `live_key_in_sandbox_code`

Error. A live key (`prv_live_`) in code meant for the sandbox.

### `sandbox_key_in_production`

Error. A sandbox key chosen in a production branch (a comparison with `"production"`, such as your environment name).

### `secret_key_in_browser`

Error. A secret key read in browser code: a `"use client"` file, or a `NEXT_PUBLIC_` or `VITE_` variable holding a secret.

### `webhook_unverified`

Error. A handler for Provenance webhook events that never checks the signature with `verifyWebhookSignature` (or the HMAC over `Provenance-Signature`).

### `webhook_parsed_before_verify`

Error. The body parsed as JSON before the signature is checked. The check needs the raw body.

### `webhook_unsafe_compare`

Warning. A hand-rolled signature compared with `===` or `==` instead of a constant-time compare, or without a timestamp tolerance.

### `idempotency_missing`

Warning. A POST that creates something without an `Idempotency-Key`. An error inside a retry loop.

### `idempotency_key_per_attempt`

Error. The idempotency key made inside the retry loop, so every retry is a new request.

### `version_unpinned`

Info. No `Provenance-Version` header or SDK version option.

### `fail_open`

Error. A `catch` or error branch around a verify or authorize call that allows the action instead of refusing it.

### `retry_on_4xx`

Warning. Retries on a 4xx other than `409` and `429`.

### `ignores_retry_after`

Warning. A `429` retried without reading `Retry-After`.

### `token_verified_loosely`

Error. An intent token verified by hand without checking `aud` and `exp`, or with algorithms other than `ES256`.

## See also

- [Developer tools](https://provenanceauth.com/docs/provenance-mcp/developer-tools.md): connect from your editor and check your sandbox requests.
- [Verify tokens](https://provenanceauth.com/docs/authorize/guides/verify-tokens.md): the binding and the revocation check.
- [Webhooks](https://provenanceauth.com/docs/integrate/webhooks.md): verify each delivery.
