Hallucination preventionUpdated 2026-12-03
How do I make a policy AI agent abstain cleanly instead of hallucinating?
Direct answer
Prevent policy agents from hallucinating by using a retrieval API that emits an explicit abstention signal when no authorized rule covers the question. Mackerel sets abstained: true and returns an empty governing array whenever no rule matches, letting your code escalate cleanly before an LLM ever drafts an answer.
Why standard retrieval breaks here
- Top-k vector search always returns k chunks—even when the corpus has zero coverage—nudging the LLM to invent an answer.
- Arbitrary cosine-similarity cutoffs drift across models, languages, and query lengths.
- Without a structured boolean signal, engineering teams cannot write reliable unit tests for out-of-domain escalations.
How Mackerel solves it
Deterministic abstained boolean
Check data.abstained in TypeScript, Python, Go, or Rust before invoking a synthesis LLM.
Clear escalation path
Route abstentions straight to a human approver, ticket queue, or clarifying question.
CI-testable invariant
Test out-of-domain prompts in bun test or pytest and assert abstained === true.
Branch on abstained before calling an LLM
const data = await fetch("https://api.runmackerel.com/v1/search", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.MACKEREL_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
corpus: "demo_sops",
query,
groups: session.groups,
}),
}).then((r) => r.json());
if (data.abstained || data.governing.length === 0) {
return { decision: "escalate", message: "No governing policy covers this question." };
}Every new workspace gets $0.50 in free credits (250 Flash searches) to validate abstention behavior in CI.
Frequently asked questions
- Does abstention work with Vercel AI SDK tool calls?
- Yes. Return the Mackerel JSON payload directly from your tool execute handler and instruct the model to state that no policy exists whenever abstained is true.