JSON Schema enum, allOf, anyOf, oneOf and not
Answer: enum restricts a value to a fixed set; it must be an array with at least one element, where each element is unique. The keywords used to combine schemas are the following:
| Keyword | Meaning | |---|---| | allOf | (AND) valid against all of the subschemas | | anyOf | (OR) valid against any of the subschemas | | oneOf | (XOR) valid against exactly one of the subschemas | | not | (NOT) the value fails the given schema |
Notes
- All of these keywords must be set to an array, and each item in it is a schema.
- Be careful with recursive schemas, as they can exponentially increase processing times.
- Pydantic generates JSON schemas compliant with JSON Schema Draft 2020-12.
See also
- ao-structured-json-schema-objects
- ao-structured-gemini-json-schema
- ao-structured-openai-structured-outputs
- ao-structured-across-providers
Claims
- id: C1 claim: enum needs a non-empty array of unique items. source: S1 evidence: "It must be an array with at least one element"
- id: C2 claim: oneOf means exactly one subschema. source: S2 evidence: "Must be valid against exactly one of the subschemas"
- id: C3 claim: Recursive schemas can be slow. source: S2 evidence: "Be careful with recursive schemas"
- id: C4 claim: Pydantic emits Draft 2020-12 schemas. source: S3 evidence: "JSON Schema Draft 2020-12"
Sources
- [S1] Understanding JSON Schema: enum. json-schema-org/website (GitHub). https://github.com/json-schema-org/website/blob/main/pages/understanding-json-schema/reference/enum.md . License: BSD-3-Clause. Accessed 2026-11-16.
- [S2] Understanding JSON Schema: schema composition. json-schema-org/website (GitHub). https://github.com/json-schema-org/website/blob/main/pages/understanding-json-schema/reference/combining.md . License: BSD-3-Clause. Accessed 2026-11-16.
- [S3] JSON Schema (Pydantic docs). pydantic/pydantic (GitHub). https://github.com/pydantic/pydantic/blob/main/docs/concepts/json_schema.md . License: MIT. Accessed 2026-11-16.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: json-schema-org/website (GitHub), Understanding JSON Schema: enum, BSD-3-Clause (https://raw.githubusercontent.com/json-schema-org/website/main/LICENSE). Copyright (c) 2022 JSON Schema Specification Authors; json-schema-org/website (GitHub), Understanding JSON Schema: schema composition, BSD-3-Clause (https://raw.githubusercontent.com/json-schema-org/website/main/LICENSE). Copyright (c) 2022 JSON Schema Specification Authors; pydantic/pydantic (GitHub), JSON Schema (Pydantic docs), MIT (https://raw.githubusercontent.com/pydantic/pydantic/main/LICENSE). Copyright (c) 2017 to present Pydantic Services Inc. and individual contributors. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: json-schema-org/website (GitHub), Understanding JSON Schema: enum, BSD-3-Clause (https://raw.githubusercontent.com/json-schema-org/website/main/LICENSE). Copyright (c) 2022 JSON Schema Specification Authors; json-schema-org/website (GitHub), Understanding JSON Schema: schema composition, BSD-3-Clause (https://raw.githubusercontent.com/json-schema-org/website/main/LICENSE). Copyright (c) 2022 JSON Schema Specification Authors; pydantic/pydantic (GitHub), JSON Schema (Pydantic docs), MIT (https://raw.githubusercontent.com/pydantic/pydantic/main/LICENSE). Copyright (c) 2017 to present Pydantic Services Inc. and individual contributors.
Cite this
iinventedlight. 2026. "JSON Schema enum, allOf, anyOf, oneOf and not." iinventedlight Library, iil:note:5vd2q6hq, version of 2026-11-16. https://iinventedlight.com/library/notes/ao-structured-json-schema-composition/. License: CC-BY-4.0.
@misc{iil_note_5vd2q6hq,
author = {{iinventedlight}},
title = {{JSON Schema enum, allOf, anyOf, oneOf and not}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-16},
url = {https://iinventedlight.com/library/notes/ao-structured-json-schema-composition/},
note = {Permanent ID iil:note:5vd2q6hq. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/ao-structured-json-schema-composition.md.