Use this file to discover Exa products, pricing, evaluations, comparisons, use cases, agent interfaces, and technical documentation before exploring further.
Python data validation libraries check that incoming data has the expected structure and types before an application uses it. A validator either builds typed objects from annotated classes or checks a plain dictionary against a separate schema. These libraries let APIs and AI agents reject malformed input before it reaches application logic.
Popularity
Pydantic has the most monthly downloads in this comparison, at 1.2B.
def iter_errors(self, data, schema=None):
"""Iterate over errors in incoming data."""
if schema is None:
return self._default_validator.iter_errors(data)
if hasattr(self._default_validator, "evolve"):
return self._default_validator.evolve(schema=schema).iter_errors(data)
return self._default_validator.iter_errors(data, schema)
fastjsonschema
Implements JSON Schema validation in Python with a focus on speed.
def _get_schema(self, argmap: ArgMap[Request], req: Request) -> ma.Schema:
"""Return a `marshmallow.Schema` for the given argmap and request.
:param argmap: Either a `marshmallow.Schema`, `dict`
of argname -> `marshmallow.fields.Field` pairs, or a callable that returns
a `marshmallow.Schema` instance.
:param req: The request object being parsed.
:rtype: marshmallow.Schema
"""
if isinstance(argmap, ma.Schema):
schema: ma.Schema = argmap
elif isinstance(argmap, type) and issubclass(argmap, ma.Schema):
schema = argmap()
elif isinstance(argmap, collections.abc.Mapping):
argmap_dict = argmap if isinstance(argmap, dict) else dict(argmap)
schema = self.schema_class.from_dict(argmap_dict)()
elif callable(argmap):
argmap_callable: ArgMapCallable[Request] = argmap # type: ignore[assignment]
schema = argmap_callable(req)
else:
raise TypeError(f"argmap was of unexpected type {type(argmap)}")
return schema
from dataclasses import dataclass
from dataclasses_json import dataclass_json
@dataclass_json
@dataclass
class User:
name: str
user = User.schema().load({"name": "Ada"})
print(user.name)
def get_converter(
converter: Optional[cattrs.Converter] = None,
) -> cattrs.Converter:
"""Adds cattrs hooks for LSP lsp_types to the given converter."""
if converter is None:
converter = cattrs.Converter()
return _hooks.register_hooks(converter)
schema
Validates data against schemas built from Python objects.
def __extract_schema_from_ref(self, schema: dict, schema_ref: dict) -> Schema:
"""Extracts a schema from a $ref if present, resolving it into native schema properties."""
if "$ref" in schema_ref:
# Resolve the reference and retrieve the schema data ref_path = schema_ref["$ref"].split("/")[-1]
schema_data = schema["components"]["schemas"].get(ref_path, {})
else:
# Use the provided schema directly if no $ref is found schema_data = schema_ref
# Convert the schema_data dictionary into a Schema with its properties properties = {}
for prop, prop_info in schema_data.get("properties", {}).items():
prop_type = prop_info.get("type", "string")
prop_description = prop_info.get("description", "")
schema_prop = Literal(prop, description=prop_description)
is_optional = prop not in schema_data.get("required", [])
if is_optional:
schema_prop = SchemaOptional(schema_prop)
properties[schema_prop] = self._map_openapi_type_to_python(prop_type, prop_info)
return Schema(properties)
FAQ
Pydantic suits most applications that model data as annotated classes. jsonschema suits data that must match a portable JSON Schema document. msgspec suits services that decode and validate JSON or MessagePack at high speed.
Pydantic builds validated Python models from annotated field types. It coerces input to those types and returns structured errors, and strict mode narrows that coercion.
Pydantic suits application models with rich validation and coercion. msgspec suits serialization paths, with typed decoding into structs and built-in support for JSON, MessagePack, YAML, and TOML.
Pydantic declares fields through type annotations on the model. marshmallow declares fields explicitly on a separate schema that deserializes, validates, and serializes objects.
jsonschema checks a parsed object against a JSON Schema document and reports each violation. fastjsonschema compiles a schema into a reusable validation function.
For coding agents
Found your data validation library? Help your agent use it.
Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.