AISchemaGate and DataContractGate

v0.4.3
io.github.nightmoose/contractgate Checked 2 hours ago Published 3 days ago

AISchemaGate validates and repairs structured LLM output against a contract, plus DataContractGate.

These tools were reported by the server itself during our smoke test (tools/list), not copied from the README.

infer_contract Infer a contract from sample events

Generate draft DataContractGate YAML from real JSON sample events via POST /contracts/infer. Does not persist. Review and write the YAML to contracts/<name>.yaml before deploying.

ParameterTypeDescription
name *stringContract name, snake_case, e.g. user_events
samples *array1–20 real event objects. Do not invent them.
descriptionstringOptional contract description

validate_events Validate events against a contract

Validate events. Pass contract_id to hit POST /v1/ingest/{id} (dry_run defaults true — no audit, quarantine, or usage). Pass yaml_content to hit POST /playground/validate per event (never persists). Exactly one of contract_id or yaml_content. 207/422 responses are returned as data so you can apply each violation's suggestion.

ParameterTypeDescription
events *arrayEvent objects to validate
contract_idstringDeployed contract UUID from deploy_contract
dry_runbooleanIngest only. Default true. Set false only after a successful dry run.
on_failstringIngest only. Default quarantine. drop counts a failure and stores neither a quarantine row nor an audit row.
yaml_contentstringIn-flight contract YAML; uses the playground, never persists

deploy_contract Deploy a contract to stable

POST /contracts/deploy — find-or-create by name, insert YAML as stable, deprecate prior stable. 409 if that (name, version) exists: bump version in the YAML. Refused while quarantine is pending. Save the returned contract_id.

ParameterTypeDescription
name *stringContract name matching the YAML name: field
yaml_content *stringFull contract YAML
deployed_bystringActor recorded on the version row
sourcestringLogical feed name, e.g. app-backend

get_quarantine List quarantined events

GET /quarantine — rejected events for the caller's org, newest first, with violation details.

ParameterTypeDescription
contract_idstringRestrict to one contract
limitintegerDefault 100, max 500
offsetinteger

list_contracts List contracts

GET /contracts — identities the API key can see.

egress_validate Validate an outbound payload

AISchemaGate structured-output check. POST /egress/{contract_id}. dry_run defaults true — no audit row or quarantine. Returns 200/207/422 so you can read min, max, pattern, enum, and compliance_mode violations and run a bounded auto-repair. Forward response.payload only — never the original body after a block or fail.

ParameterTypeDescription
contract_id *stringDeployed contract UUID
events *arrayOutbound payload objects to validate
dispositionstringDefault block. block = drop failing records from payload; fail = reject entire batch; tag = pass through with flags.
dry_runbooleanDefault true. Set false only after a successful dry run — live calls write audit and quarantine rows unless on_fail is drop.
on_failstringDefault quarantine. drop counts a failure and stores neither a quarantine row nor an audit row. Ignored when the contract locks on_fail.
versionstringPin a specific contract version. Default: latest stable.

get_drop_counts List dropped-record counts

GET /contracts/{id}/drop-counts. Minute buckets of dropped failures by reason, kept 30 days. Counts and failure metadata only — never record contents.

ParameterTypeDescription
contract_id *stringDeployed contract UUID
hoursintegerLookback in hours. Default 24.