# contracts.validate

Check proposed schema rules and examples without publishing or recording.

Capability: op_sys_contracts_validate
Protocol: op-sys.capabilities.v1
Runtime: 0.3.0
Availability: Local or hosted ledger authority
Optional integration: false
Canonical page: /docs/reference/op_sys_contracts_validate

## Authority

Publication and configuration require ledger administration. An append grant never authorizes changing the schema or grants.

## Invocation

CLI, SDK and MCP use the same operation and arguments; where a hosted HTTP binding exists, its route carries the same domain contract. Host paths and environment references refer to the runtime host. Request template: replace placeholder IDs and supply complete contract-specific objects before use. This is not a complete runnable workflow.

### CLI

```sh
op-sys --output json tools call op_sys_contracts_validate \
  --arguments '{"payload_schema":{}}'
```

### Python SDK

```python
import json
from op_sys import OpSys

client = OpSys()
arguments = json.loads("{\"payload_schema\":{}}")
result = client.capabilities.call(
    "op_sys_contracts_validate", arguments
)
print(result)
```

### MCP (initialized connection)

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "op_sys_contracts_validate",
    "arguments": {
      "payload_schema": {}
    }
  }
}
```

### HTTP

```sh
curl --fail-with-body --request POST "$VEYLAR_ENDPOINT/v1/contracts/validate" \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H "X-Veylar-Tenant: $TENANT_ID" \
  -H 'Content-Type: application/json' \
  --data '{"payload_schema":{}}'
```

Named CLI command: op-sys contracts validate (use --help for flags).

SDK convenience: client.contracts.validate(…). The capability adapter may wrap the result.

## Parameters

### payload_schema

Required; object. 



### file_rules

Optional; object. 


```json
{
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "media_types": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1,
        "maxLength": 128,
        "pattern": "^(\\*/\\*|[a-z0-9][a-z0-9!#$&^_.+-]*/[a-z0-9][a-z0-9!#$&^_.+-]*)$"
      },
      "maxItems": 64,
      "uniqueItems": true
    },
    "max_bytes": {
      "type": "integer",
      "minimum": 0,
      "maximum": 1073741824
    },
    "max_items": {
      "type": "integer",
      "minimum": 0,
      "maximum": 16
    }
  },
  "required": [
    "media_types",
    "max_bytes",
    "max_items"
  ]
}
```


### examples

Optional; array. 

maxItems: 16
```json
{
  "type": "array",
  "items": {},
  "maxItems": 16
}
```


### Complete input schema

```json
{
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "payload_schema": {
      "type": "object"
    },
    "file_rules": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "media_types": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128,
            "pattern": "^(\\*/\\*|[a-z0-9][a-z0-9!#$&^_.+-]*/[a-z0-9][a-z0-9!#$&^_.+-]*)$"
          },
          "maxItems": 64,
          "uniqueItems": true
        },
        "max_bytes": {
          "type": "integer",
          "minimum": 0,
          "maximum": 1073741824
        },
        "max_items": {
          "type": "integer",
          "minimum": 0,
          "maximum": 16
        }
      },
      "required": [
        "media_types",
        "max_bytes",
        "max_items"
      ]
    },
    "examples": {
      "type": "array",
      "items": {},
      "maxItems": 16
    }
  },
  "required": [
    "payload_schema"
  ]
}
```

## Behavior

- Use capabilities.list schema_profile for the supported schema language and limits.
- If examples are omitted, the root payload_schema.examples annotation supplies them. An explicit examples list replaces those checks.
- This operation validates only caller-supplied schema/file rules and example payload shapes. It does not inspect stored data, publish/admit a contract, validate attachment bytes, or prove assertions true.
- Publishing a contract does not admit it. Configure the admitted references and default separately.
- Read the current revision before a configuration update. On conflict, re-read and reconcile intent; never blindly increase the expected revision.
- Historical definitions and contract versions remain accessible. Changes govern new admission without rewriting accepted records.

## Response

Returns a validation-only report with schema validity and per-example results. No acceptance or permission is granted.

### Complete result JSON Schema

```json
{
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "validator": {
      "type": "string",
      "minLength": 1,
      "maxLength": 128
    },
    "validation_only": {
      "const": true
    },
    "valid": {
      "type": "boolean",
      "description": "True only when the proposed schema and every supplied example pass validation. A successful operation can return false; callers must inspect this field."
    },
    "schema_valid": {
      "type": "boolean",
      "description": "Whether the proposed schema is supported and well formed, independently of example validity."
    },
    "issues": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "code": {
            "type": "string",
            "enum": [
              "contract_invalid",
              "payload_invalid",
              "limit_exceeded"
            ]
          },
          "field": {
            "type": "string",
            "minLength": 1,
            "maxLength": 512
          },
          "message": {
            "type": "string",
            "minLength": 1,
            "maxLength": 512
          }
        },
        "required": [
          "code",
          "field",
          "message"
        ]
      },
      "maxItems": 1
    },
    "examples": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "index": {
            "type": "integer",
            "minimum": 0
          },
          "valid": {
            "type": "boolean"
          },
          "issue": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "code": {
                "type": "string",
                "enum": [
                  "contract_invalid",
                  "payload_invalid",
                  "limit_exceeded"
                ]
              },
              "field": {
                "type": "string",
                "minLength": 1,
                "maxLength": 512
              },
              "message": {
                "type": "string",
                "minLength": 1,
                "maxLength": 512
              }
            },
            "required": [
              "code",
              "field",
              "message"
            ]
          }
        },
        "required": [
          "index",
          "valid"
        ]
      },
      "maxItems": 16
    }
  },
  "required": [
    "validator",
    "validation_only",
    "valid",
    "schema_valid",
    "issues",
    "examples"
  ]
}
```


[Runtime output field catalog](/docs/output-contracts.json) (descriptive contracts, not JSON Schema validators).

CLI: use --output json. For tools call, read the operation result at payload.tool.result; payload.tool.name identifies the capability. The outer envelope is {schema_version: "v1", payload: {tool: {name, result}}}.

Python: client.capabilities.call(name, arguments) returns the operation result. SDK exceptions preserve reason and code.

MCP: tools/call returns JSON text and structuredContent. Application failures set isError; inspect reason/code instead of matching message text.

Related resource schemas (not necessarily a complete operation response):
- [ledger-core.v1.schema.json](/docs/schemas/ledger-core.v1.schema.json)

## Errors and recovery

[Ledger limits and operation catalog](/docs/ledger-core.json)

Canonical operation: contracts.validate

Permissions: client context

Retry: read_only; concurrency: none

Codes: invalid_input, contract_invalid, payload_invalid, contract_not_admitted, permission_denied, not_found, revision_conflict, operation_conflict, unsupported, authority_unavailable, outcome_uncertain, outcome_expired, validation_context_unavailable, file_unavailable, integrity_failure, ledger_archived, ledger_deleted, resnapshot_required, identity_changed, authority_fenced, withdrawal_requires_resolution, limit_exceeded, rate_limited, payment_required

[HTTP status mappings and schemas](/docs/ledger-core.openapi.json)

- permission_denied: Use a principal with the required ledger permissions.
- revision_conflict: Inspect the current revision before revising.

Family reasons are representative, not exhaustive.

A timeout is not proof that a write failed. Reuse the documented retry identity, batch, offset or mutation ID. If this operation has no documented retry identity, inspect its state before repeating it.

On authorization failure, correct the configured identity or grants; do not change the local actor to impersonate a hosted principal. On validation failure, correct the input against the published schema and selected contract.

On a revision or state conflict, retrieve current state and reconcile intent. Do not automatically overwrite a competing update. Preserve unknown additive response fields when building consumers.

## Source manuals

- [local-records](/docs/raw/manuals/local-records.md)
- [shared-records](/docs/raw/manuals/shared-records.md)
- [public-capabilities](/docs/raw/manuals/public-capabilities.md)
- [command-output-schema](/docs/raw/manuals/command-output-schema.md)
