API Reference
Business Contracts
Business Contracts validate what your AI output means — not just its structure. Define field-level rules and semantic checks in plain English. When a rule is violated, Reliant flags the output or blocks it automatically before it reaches your application.
How it works
Pass a contract_id in your /execute request. After the LLM output passes JSON schema validation, Reliant evaluates it against your business rules — first simple rules (instant, no LLM cost), then semantic rules (Claude as judge).
POST /execute
X-Reliant-Key: rel_...
Content-Type: application/json
{
"prompt": "Extract invoice data from: Invoice #1234, Amount: $5,000 USD",
"schema_id": "invoice-extraction",
"contract_id": "bc_...",
"provider": "anthropic",
"model": "claude-sonnet-4-20250514",
"user_id": "your-user-id"
}
Response — contract passed
{
"success": true,
"status": "success",
"output": { "amount": 5000, "currency": "USD", "invoice_id": "1234" },
"contract_violated": false,
"contract_violations": null,
"contract_id": "bc_...",
"metadata": { ... }
}
Response — contract violated (on_violation: flag)
The output is returned with contract_violated: true and a list of violations. Your app receives the output and decides what to do.
{
"success": true,
"status": "success",
"output": { "amount": -500, "currency": "USD" },
"contract_violated": true,
"contract_violations": [
{
"rule": "amount must be > 0",
"field": "amount",
"expected": "> 0",
"got": "-500",
"type": "simple"
}
],
"contract_id": "bc_...",
"metadata": { ... }
}
Response — contract violated (on_violation: block)
The safe fallback from your schema is returned. The output never reaches your application.
{
"success": false,
"status": "contract_blocked",
"output": { "amount": null, "currency": null },
"contract_violated": true,
"contract_violations": [
{
"rule": "amount must be > 0",
"field": "amount",
"type": "simple"
}
],
"contract_id": "bc_...",
"metadata": { ... }
}
Rule types
① Simple rules
Evaluated instantly against the output fields — no LLM cost. Use dot notation for nested fields.
| Operator | Description | Example |
|---|
not_null | Field must exist and not be null | {"field":"email","op":"not_null"} |
not_empty | Field must not be null, empty string, or empty array | {"field":"name","op":"not_empty"} |
eq | Equals a value | {"field":"currency","op":"eq","value":"USD"} |
neq | Not equals | {"field":"status","op":"neq","value":"rejected"} |
gt | Greater than (number) | {"field":"amount","op":"gt","value":0} |
gte | Greater than or equal | {"field":"confidence","op":"gte","value":0.7} |
lt | Less than | {"field":"risk_score","op":"lt","value":0.9} |
lte | Less than or equal | {"field":"rate","op":"lte","value":1.0} |
in | Value is in an allowed list | {"field":"sentiment","op":"in","value":["positive","negative","neutral"]} |
not_in | Value is not in a blocked list | {"field":"category","op":"not_in","value":["spam","adult"]} |
matches | Value matches a regex pattern | {"field":"email","op":"matches","value":"^[^@]+@[^@]+\\.[^@]+$"} |
② Semantic rules
Evaluated by Claude Haiku as a judge. Write rules in plain English — they run only after all simple rules pass, to minimize token usage.
[
{
"description": "The extracted amount must match the currency mentioned in the input",
"weight": "required"
},
{
"description": "The summary must be written in professional tone without informal language",
"weight": "important"
},
{
"description": "If a phone number is extracted, it should follow the format of the country mentioned",
"weight": "preferred"
}
]
| Weight | Effect |
|---|
required | Violation triggers flag or block depending on on_violation |
important | Violation triggers flag only, regardless of on_violation |
preferred | Logged but does not trigger violation |
Contract management endpoints
POST /contracts
Create a business contract.
{
"name": "Invoice Quality Gate",
"description": "Ensures extracted invoice data is valid for processing",
"schema_id": "invoice-extraction",
"user_id": "your-user-id",
"on_violation": "flag",
"rules": [
{ "field": "amount", "op": "gt", "value": 0, "message": "Amount must be positive" },
{ "field": "currency", "op": "in", "value": ["USD", "EUR", "BRL"] },
{ "field": "invoice_id", "op": "not_empty" }
],
"semantic_rules": [
{
"description": "The extracted amount must match the currency and value mentioned in the input text",
"weight": "required"
}
]
}
GET /contracts
List all contracts for the authenticated project.
PUT /contracts/:id
Update a contract. Changes take effect immediately on the next execution.
DELETE /contracts/:id
Delete a contract. Existing executions that referenced it are not affected.
Full example with SDK
import { Reliant } from 'reliant-js'
const reliant = new Reliant({ apiKey: 'rel_...' })
const result = await reliant.execute({
prompt: 'Extract invoice data from: Invoice #1234, Amount: -500 USD',
schemaId: 'invoice-extraction',
contractId: 'bc_...',
provider: 'anthropic',
model: 'claude-sonnet-4-20250514',
userId: 'your-user-id',
})
if (result.contract_violated) {
console.log('Contract violations:', result.contract_violations)
// [{ rule: 'amount must be > 0', field: 'amount', got: '-500' }]
if (result.status === 'contract_blocked') {
// safe_fallback was returned — do not process
console.log('Output blocked by contract')
} else {
// flagged — output available but needs review
console.log('Output flagged for review:', result.output)
}
} else {
// Fully trusted output — passed JSON schema + business contract
console.log('Trusted output:', result.output)
}
Tip: Simple rules run first — if they fail, semantic rules are skipped entirely. This minimizes LLM cost: you only pay for semantic evaluation when field-level constraints are satisfied.