An Agent for evaluating the groundedness of LLM responses
This repository provides dependency-free Python primitives for black-box groundedness evaluation of Copilot-style agents. The detector treats each answer as a trace across:
- user prompt
- Copilot orchestration
- knowledge and tool selection
- evidence utilization
- final answer and citations
The core evaluator computes these quality signals:
grounding_route_correctnessevidence_support_precisioncitation_correctnessevidence_coverageevidence_dependencegrounding_policy_adherencetool_output_utilizationabstention_correctnesscross_turn_grounding_retention
from ai_groundedness_detector import (
AgentRun,
Claim,
DetectorTrace,
Evidence,
GroundednessDetector,
GroundingPolicy,
)
run = AgentRun(
trace=DetectorTrace(
evaluation_run_id="run-20260915-0042",
agent_id="agent-j-dev",
agent_version="2.4.1",
conversation_id="copilot-conversation-id",
turn_id=3,
scenario_id="seismic-product-guidance",
grounding_configuration_version="grounding-v7",
),
prompt="According to the approved guidance, how often does promotion run?",
answer="The promotion runs monthly.",
observed_route="Seismic",
evidence=(Evidence(id="e1", source="Seismic", text="Promotion runs monthly."),),
claims=(
Claim(
id="c1",
text="The promotion runs monthly.",
supporting_evidence_ids=("e1",),
cited_evidence_ids=("e1",),
),
),
)
result = GroundednessDetector().evaluate(
run,
GroundingPolicy(required_source="Seismic", expected_tool="search_seismic"),
)
print(result.metrics)For evidence-dependence checks, evaluate a full run together with controlled
variants such as knowledge-removed, supporting-document-changed,
distractor-added, and tool-unavailable. The evaluator compares claim
behavior across those variants to determine whether the final answer depended on
the configured enterprise evidence rather than merely being supportable by it.
Run the focused tests with:
python -m unittest