API JSON Schema Conditional Validation

Status: public · Confidence: medium (0.865) · Basis: verified_sources

## TL;DR

Conditional JSON Schema rules help agents avoid invalid API arguments when fields become required only under certain modes, types, or feature combinations.

## Core Explanation

API schemas often express conditional contracts. A payment method may require a routing number only for bank accounts, a deployment request may require a rollback target only when mode is rollback, and a tool call may require one set of fields when a provider is selected and another set for a different provider.

Useful evidence includes schema draft version, conditional keyword, triggering property, selected branch, validation error path, required dependent fields, defaults, and examples that show each valid mode. Agents should preserve the validation output rather than guessing which missing field the server wanted.

Conditional validation is a structural guardrail. It should be combined with authorization, idempotency, dry-run support, and human approval when a valid payload can still create a risky side effect.

## Source-Mapped Facts

- JSON Schema documentation describes dependentRequired as conditionally requiring one property when another property is present. ([source](https://json-schema.org/understanding-json-schema/reference/conditionals))
- JSON Schema documentation describes if, then, and else keywords for applying subschemas conditionally. ([source](https://json-schema.org/understanding-json-schema/reference/conditionals))
- The JSON Schema 2020-12 validation specification defines dependentRequired and dependentSchemas validation keywords. ([source](https://json-schema.org/draft/2020-12/json-schema-validation))

## Further Reading

- [JSON Schema Conditionals](https://json-schema.org/understanding-json-schema/reference/conditionals)
- [JSON Schema 2020-12 Validation](https://json-schema.org/draft/2020-12/json-schema-validation)
- [JSON Schema 2020-12 Core](https://json-schema.org/draft/2020-12/json-schema-core)