Skip to main content
Some requirements depend on a field’s value, not just its presence. If delivery_method is "shipping", you need a full address. If it is "pickup", you need a pickup location instead. JSON Schema’s if / then / else keywords let you express that branching logic directly in the schema. This is different from dependentRequired. Use dependentRequired when fields travel together based only on presence. Use if / then / else when the required fields depend on a specific value. Pydantic and Zod do not generate JSON Schema with if / then / else. If you need conditional constraints, write the JSON Schema directly.

Use case

Checkout fulfillment where delivery_method="shipping" requires address, while delivery_method="pickup" requires pickup_location.

Schema pattern

JSON Schema
curl

Example outputs

Shipping:
Pickup:

Why this works

Without conditional requirements, the model might produce a shipping request with no address, or a pickup request with no pickup location. Your application would then need to infer which fields are missing and retry or repair the payload. if / then / else prevents that at generation time. The model sees that the required field set changes with delivery_method, and it produces the matching branch. Use this pattern when the decision depends on a value. For presence-only dependencies like “if vat_id exists, require billing_country”, use Field Dependencies.