dependentRequired encodes these relationships directly in the schema: if field A appears, fields B and C must also appear.
This is simpler than if/then because it doesn’t depend on a field’s value, only its presence. It’s the right tool when fields travel in groups.
Use case
Customer billing details wherevat_id, company_name, and billing_country must all appear together. If the customer is a business with a VAT ID, you need the other two fields to validate and process it.
Schema pattern
JSON Schema
dependentRequired in the generated JSON Schema. For structured generation, prefer raw JSON Schema whenever this dependency needs to be part of the contract you send to the model.
curl
Example outputs
Valid business record:Why this works
WithoutdependentRequired, the model might produce {"customer_type": "business", "vat_id": "FR-12345678"}: a business record with a VAT ID but no company name or billing country. Your application would then need to either reject the record and retry, or patch the missing fields from another source. Both options are expensive.
dependentRequired prevents this at generation time. The model sees the constraint and produces all related fields together, or none of them. This keeps your application code simple: you validate once and process, rather than validate-then-repair.
If this dependency needs to be part of the generated schema contract, use raw JSON Schema in response_format. Use the Pydantic and Zod patterns only when you are validating after generation inside your own application.