I’m trying to extract data using this JSON schema (I’m using a $ref
inside the $defs
- or more concrete I want an opportunity to reference a contact):
{
"type": "object",
"properties": {
"contacts": {
"type": "array",
"items": {
"$ref": "#/$defs/contact"
}
},
"accounts": {
"type": "array",
"items": {
"$ref": "#/$defs/account"
}
},
"opportunities": {
"type": "array",
"items": {
"$ref": "#/$defs/opportunity"
}
}
},
"required": ["contacts", "accounts", "opportunities"],
"additionalProperties": false,
"$defs": {
"contact": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"email": {
"type": ["string", "null"]
},
"job_title": {
"type": ["string", "null"]
},
"phone": {
"type": ["string", "null"]
},
"name_prefix": {
"type": ["string", "null"]
},
"gender": {
"type": ["string", "null"]
},
"language": {
"type": ["string", "null"]
},
"account_name": {
"type": ["string", "null"]
}
},
"required": ["name", "email", "job_title", "phone", "name_prefix", "gender", "language", "account_name"],
"additionalProperties": false
},
"account": {
"type": "object",
"properties": {
"name": {
"type": "string"
}
},
"required": ["name"],
"additionalProperties": false
},
"opportunity": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"notes": {
"type": "string"
},
"investment_sum": {
"type": ["number", "null"]
},
"valuation": {
"type": ["number", "null"]
},
"pre_money": {
"type": ["boolean", "null"]
},
"investment_type": {
"type": ["string", "null"],
"enum": ["share_deal", "convertible"]
},
"investment_round": {
"type": ["string", "null"],
"enum": ["Preseed", "Seed", "Series A", "Series B", "Series C", "Series D", "Series E", "Series F"]
},
"account_name": {
"type": ["string", "null"]
},
"arr": {
"type": ["number", "null"]
},
"mrr": {
"type": ["number", "null"]
},
"number_of_customers": {
"type": ["number", "null"]
},
"number_of_active_users": {
"type": ["number", "null"]
},
"month_on_month_growth": {
"type": ["number", "null"]
},
"year_on_year_growth": {
"type": ["number", "null"]
},
"contacts": {
"type": "array",
"items": {
"$ref": "#/$defs/contact"
}
}
},
"required": ["name", "notes", "investment_sum", "valuation", "pre_money", "investment_type", "investment_round", "account_name", "arr", "mrr", "number_of_customers", "number_of_active_users", "month_on_month_growth", "year_on_year_growth", "contacts"],
"additionalProperties": false
}
}
}
When I post this to the API I’ll get a 400 Bad Request error: Invalid schema for response_format ‘data_extraction’. Please ensure it is a valid JSON Schema.
When I use an external validator the schema is marked as valid.
When I inline all the contact properties inside the related_contacts array the extraction works as expected.
Is it possible that $ref inside $defs is not supported?