jsonschema
JSON Schema validation library for Python — validates JSON/dict data against JSON Schema drafts (draft-07, draft-2019-09, draft-2020-12). jsonschema features: jsonschema.validate() one-shot validation, jsonschema.Draft202012Validator for explicit draft selection, validator.iter_errors() for all errors not just first, best_match() for human-readable error selection, schema referencing ($ref, $defs), format validators (email, date, uri), custom validators, jsonschema.exceptions.ValidationError with path and schema info, and format checking with jsonschema[format-nongpl] extras. Standard for validating OpenAPI request/response bodies, config files, and agent-generated structured outputs.
Score Breakdown
⚙ Agent Friendliness
🔒 Security
Pure validation library — no network calls by default. $ref to remote URLs (http/https) can trigger network requests; disable with custom RefResolver for untrusted schemas. Schema itself is not executable — no code injection risk.
⚡ Reliability
Best When
Validating JSON data against JSON Schema specs (OpenAPI schemas, config schemas, agent output schemas) — jsonschema is the reference Python implementation supporting all JSON Schema drafts with detailed error reporting and $ref resolution.
Avoid When
You need type coercion (use pydantic), Python object validation, or high-throughput validation (use fastjsonschema).
Use Cases
- • Agent output validation — schema = {'type': 'object', 'required': ['action', 'params'], 'properties': {'action': {'type': 'string'}, 'params': {'type': 'object'}}}; jsonschema.validate(agent_output, schema) — validate LLM-generated JSON against schema; agent structured output pipeline ensures valid tool calls before execution; ValidationError caught and fed back to LLM for retry
- • Agent API request validation — validator = jsonschema.Draft202012Validator(openapi_schema['components']['schemas']['CreateUser']); errors = list(validator.iter_errors(request_body)) — validate incoming API request body; agent API gateway validates all requests before processing; collect all errors not just first with iter_errors()
- • Agent config file validation — schema = json.load(open('config-schema.json')); jsonschema.validate(yaml.safe_load(open('config.yaml')), schema) — validate YAML/JSON config against schema; agent validates config at startup before any processing; clear error paths show exactly which config field is wrong
- • Agent response schema checking — errors = list(validator.iter_errors(api_response)); best = jsonschema.exceptions.best_match(errors); raise ValueError(f'API response invalid: {best.message}') — validate third-party API response against expected schema; agent detects API contract violations before processing bad data
- • Agent dynamic schema generation — schema = {'type': 'array', 'items': {'type': 'object', 'properties': {k: {'type': 'string'} for k in required_fields}}}; jsonschema.validate(data, schema) — programmatically build schema from field list; agent validates dynamic data structures where schema varies by context
Not For
- • Pydantic-style type coercion — jsonschema validates only, doesn't convert types; '42' doesn't validate as integer; use pydantic for type coercion + validation in one step
- • Python dataclass validation — jsonschema validates dicts/JSON; for Python object validation use pydantic or attrs
- • Performance-critical validation — jsonschema is pure Python and slow for high-throughput validation; use fastjsonschema for 5-10x faster validation in hot paths
Interface
Authentication
No auth — local validation library.
Pricing
jsonschema is MIT licensed. Free for all use.
Agent Metadata
Known Gotchas
- ⚠ jsonschema.validate() raises on first error only — jsonschema.validate(data, schema) raises ValidationError on first problem; agent code collecting all validation errors must use: v = jsonschema.Draft202012Validator(schema); errors = list(v.iter_errors(data)) — collect all errors before reporting back to LLM for one-shot retry
- ⚠ Draft version matters for $schema keyword — JSON Schema draft-07 uses 'definitions', draft-2019-09+ uses '$defs'; schema using wrong draft validator raises SchemaError or silently ignores keywords; always use Draft202012Validator unless schema explicitly declares older $schema URI
- ⚠ format validation not enforced by default — jsonschema.validate(data, {'type': 'string', 'format': 'email'}) does NOT validate email format by default; format checking requires: jsonschema.validate(data, schema, format_checker=jsonschema.FormatChecker()); agent schema validation for email/date/URI must explicitly enable format checker
- ⚠ $ref resolution requires referencing store or registry — schema with $ref to external file fails unless using RefResolver or jsonschema.Registry; agent code loading schemas from multiple files must: resolver = jsonschema.RefResolver('file:///path/', schema); validator = Draft202012Validator(schema, resolver=resolver)
- ⚠ error.path is a deque not list — ValidationError.path is collections.deque; agent code accessing error.path[0] works but list(error.path) needed for full path; error.absolute_path gives full path as deque from root; convert with list(error.absolute_path) for readable key path
- ⚠ additionalProperties defaults to true — {'type': 'object', 'properties': {'name': {'type': 'string'}}} allows any extra keys; agent schema for strict output validation must add 'additionalProperties': false to reject unexpected fields from LLM; commonly missed causing silent extra field acceptance
Alternatives
Full Evaluation Report
Comprehensive deep-dive: security analysis, reliability audit, agent experience review, cost modeling, competitive positioning, and improvement roadmap for jsonschema.
AI-powered analysis · PDF + markdown · Delivered within 30 minutes
Package Brief
Quick verdict, integration guide, cost projections, gotchas with workarounds, and alternatives comparison.
Delivered within 10 minutes
Score Monitoring
Get alerted when this package's AF, security, or reliability scores change significantly. Stay ahead of regressions.
Continuous monitoring
Scores are editorial opinions as of 2026-03-06.