Discrepancy between the Chat UI and API while using nested JSON Schema for structured extraction
Context
Goal: Extract a contract summary using a nested Draft-07 schema with definitions and multiple $refs.
Schema characteristics:
Draft-07, deep nesting, $ref to #/definitions/*, arrays of objects, recursive type (milestoneItem has sub_milestones referencing itself), nullable unions (e.g., "type": ["string","null"]), and tight required lists.
Example top-level keys: meta, contract_level, commercial_terms, invoicing_requirements, travel_policies, exceptions_and_rejection_risks.
(Full schema attached below.)
What works
In the Landing AI Chat UI, the model returns valid JSON that conforms to the schema. Extraction quality and structure look correct.
What fails
When we call the API and pass the same schema inline, the extraction either:
Is rejected as an invalid schema, or
Returns partial/flat JSON that ignores $ref/nested requirements, or
Fails validation on fields that are required in nested objects (e.g., contract_level.milestones[].sub_milestones, evidenceArray), even though the Chat UI fills them.
Unfortunately, the API response does not consistently include a clear error explaining which part of the schema is unsupported.
Repro steps
Call the extraction API with the attached schema inline as the tool/response format.
Document: any typical SOW/contract PDF.
Result: either schema rejection or JSON that omits nested $ref-driven properties the Chat UI provides.
What we need
Confirmation whether inline nested schemas with local $refs and recursion are fully supported in the API.
If not, recommended approach:
Host the schema at a URL?
Flatten the schema (remove $ref and recursion)? - we are not getting what we are looking for
Disallow nullable unions or adjust types to singletons?
Set specific flags (e.g., enable local $ref resolution) or headers?
Example of a minimal, API-compatible nested schema that uses $ref and arrays of objects.
Guidance on returning validator errors in the API response (pointer to failing path).
I’ve included the exact schema below for your reference. If you can share a sample API payload (request & response) that uses a similar nested structure successfully, that would be ideal.
Thanks so much!
{ "$schema": "http://json-schema.org/draft-07/schema#", "title": "ContractExtraction", "type": "object", "required": ["meta", "contract_level", "commercial_terms", "invoicing_requirements", "travel_policies", "exceptions_and_rejection_risks"], "properties": { "meta": { "type": "object", "required": ["adapter_model", "source_filename", "extraction_timestamp"], "properties": { "adapter_model": { "type": "string" }, "source_filename": { "type": "string" }, "extraction_timestamp": { "type": "string", "format": "date-time" } } }, "contract_level": { "type": "object", "required": ["contract_number","project_name","country","scope","project_manager","contract_value","milestones"], "properties": { "contract_number": { "$ref": "#/definitions/fieldString" }, "project_name": { "$ref": "#/definitions/fieldString" }, "country": { "$ref": "#/definitions/fieldString" }, "scope": { "$ref": "#/definitions/fieldString" }, "project_manager": { "$ref": "#/definitions/fieldString" }, "contract_value": { "type": "object", "required": ["value","currency","raw","confidence","explanation","evidence"], "properties": { "value": { "type": ["number","null"] }, "currency": { "type": ["string","null"] }, "raw": { "type": ["string","null"] }, "confidence": { "type": "number", "minimum": 0.0, "maximum": 1.0 }, "explanation": { "type": "string" }, "evidence": { "$ref": "#/definitions/evidenceArray" } } }, "milestones": { "type": "array", "items": { "$ref": "#/definitions/milestoneItem" } } } }, "commercial_terms": { "type": "object", "required": ["payment_terms","standard_rate","overtime_rate"], "properties": { "payment_terms": { "type": "object", "required": ["text","net_days","confidence","explanation","evidence"], "properties": { "text": { "type": ["string","null"] }, "net_days": { "type": ["integer","null"] }, "confidence": { "type": "number", "minimum": 0.0, "maximum": 1.0 }, "explanation": { "type": "string" }, "evidence": { "$ref": "#/definitions/evidenceArray" } } }, "standard_rate": { "$ref": "#/definitions/rateField" }, "overtime_rate": { "$ref": "#/definitions/rateField" } } }, "invoicing_requirements": { "type": "object", "required": ["requirements"], "properties": { "requirements": { "type": "array", "items": { "type": "object", "required": ["statement","confidence","explanation","evidence"], "properties": { "statement": { "type": "string" }, "confidence": { "type": "number", "minimum": 0.0, "maximum": 1.0 }, "explanation": { "type": "string" }, "evidence": { "$ref": "#/definitions/evidenceArray" } } } } } }, "travel_policies": { "type": "object", "required": ["policies"], "properties": { "policies": { "type": "array", "items": { "type": "object", "required": ["statement","confidence","explanation","evidence"], "properties": { "statement": { "type": "string" }, "confidence": { "type": "number", "minimum": 0.0, "maximum": 1.0 }, "explanation": { "type": "string" }, "evidence": { "$ref": "#/definitions/evidenceArray" } } } } } }, "exceptions_and_rejection_risks": { "type": "object", "required": ["items"], "properties": { "items": { "type": "array", "items": { "type": "object", "required": ["statement","confidence","explanation","evidence"], "properties": { "statement": { "type": "string" }, "confidence": { "type": "number", "minimum": 0.0, "maximum": 1.0 }, "explanation": { "type": "string" }, "evidence": { "$ref": "#/definitions/evidenceArray" } } } } } } }, "definitions": { "fieldString": { "type": "object", "required": ["value","confidence","explanation","evidence"], "properties": { "value": { "type": ["string","null"] }, "confidence": { "type": "number", "minimum": 0.0, "maximum": 1.0 }, "explanation": { "type": "string" }, "evidence": { "$ref": "#/definitions/evidenceArray" } } }, "rateField": { "type": "object", "required": ["amount","currency","unit","confidence","explanation","evidence"], "properties": { "amount": { "type": ["number","null"] }, "currency": { "type": ["string","null"] }, "unit": { "type": ["string","null"] }, "confidence": { "type": "number", "minimum": 0.0, "maximum": 1.0 }, "explanation": { "type": "string" }, "evidence": { "$ref": "#/definitions/evidenceArray" } } }, "evidenceArray": { "type": "array", "items": { "type": "object", "required": ["snippet"], "properties": { "snippet": { "type": "string" }, "page": { "type": ["integer","null"] }, "section": { "type": ["string","null"] } } } }, "milestoneItem": { "type": "object", "required": ["name","percent_of_contract_value","amount","currency","invoice_trigger","dates","confidence","explanation","evidence","sub_milestones"], "properties": { "name": { "type": ["string","null"] }, "percent_of_contract_value": { "type": ["number","null"] }, "amount": { "type": ["number","null"] }, "currency": { "type": ["string","null"] }, "invoice_trigger": { "type": ["string","null"] }, "dates": { "type": "object", "properties": { "planned": { "type": ["string","null"] }, "actual": { "type": ["string","null"] } } }, "confidence": { "type": "number", "minimum": 0.0, "maximum": 1.0 }, "explanation": { "type": "string" }, "evidence": { "$ref": "#/definitions/evidenceArray" }, "sub_milestones": { "type": "array", "items": { "$ref": "#/definitions/milestoneItem" } } } } } }