Concept overview: The Requirements System explains the design and trade-offs.Prerequisites: The Requirements System, Quick Start complete,
pip install mellea.
Custom verifiers are Python functions that inspect LLM output and return a
ValidationResult. Mellea calls them as part of the IVR loop: when a verifier
returns False, Mellea sends the reason back to the model and retries.
The simple_validate shortcut
For checks that only need the most recent output string, use simple_validate:
simple_validate when your logic only needs the output text and has no
side effects. For anything beyond that — JSON parsing with error details,
external API calls, access to conversation history — write a full validation
function.
Writing a full validation function
A validation function receives theContext object and returns a
ValidationResult. The most common pattern is to inspect the last model output:
Requirement:
Common validation patterns
JSON validity
Pydantic schema conformance
Regex patterns
External API or database check
Validation functions are synchronous. For checks that call external systems, make the call inline:
Note: External calls in validators add latency to every validation attempt.
Keep them fast and idempotent — the validator may be called multiple times
per instruct() call if the IVR loop retries.
Using ValidationResult.score
Some validators produce a numeric confidence score rather than a binary result.
Include it for observability and to support scoring-based sampling strategies:
Composing multiple verifiers
Mixsimple_validate and full validation functions freely in a requirements list:
reason strings in the repair request, so the model
can address multiple issues in a single pass.
Debugging verifier failures
Usereturn_sampling_results=True to inspect which requirements failed and why:
See also: The Requirements System | Instruct, Validate, Repair