validators
module wittgenstein_agent_guardrails.validators
Generic pydantic-ai output_validator factory for grounding checks.
Functions
-
make_grounding_validator — Build a pydantic-ai
@agent.output_validatorthat rejects answers produced without retrieving any grounding facts this turn.
wittgenstein_agent_guardrails.validators.make_grounding_validator
make_grounding_validator(facts_accessor: Callable[[DepsT], list], ungrounded_message: str = DEFAULT_UNGROUNDED_MESSAGE) → Callable[[Any, str], Any]
Build a pydantic-ai @agent.output_validator that rejects answers
produced without retrieving any grounding facts this turn.
facts_accessor(ctx.deps) should return whatever the agent's tools
accumulated during the run (e.g. knowledge-graph triplets fetched by a
query tool). This is a cheap circuit breaker for "answered without
looking anything up" — it does not perform entailment/NLI between the
answer text and the facts, mirroring the pragmatic, narrow checks
already proven in production (e.g. an NLQ chat agent's
check that only verifies that a query
actually ran). Raising pydantic_ai.ModelRetry is pydantic-ai's retry
signal — it tells the model to try again with corrected output instead
of crashing the whole agent run.
Raises
-
ModelRetry