Sections in this lesson
Verification Tools & Structured Answers
Use arithmetic for numbers, compilation or pinned API documentation for code, and authorized reference data for facts.
Reviewed: · Content owner: Interview Preparator
What you will learn
- Choose a verifier for the claim
- Treat verifier output as fallible
- Keep execution narrow
Before you start
The flow
- 1.Identify scope
- 2.Inspect evidence
- 3.Apply host control
- 4.Run negative cases
- 5.Compare benign behavior
- 6.Review remaining risks
Choose a verifier for the claim
Use arithmetic for numbers, compilation or pinned API documentation for code, and authorized reference data for facts. Asking the same model to repeat its answer is not independent verification. A passing JSON parser establishes syntax, not meaning.
The fixture verifier accepts only key, value and sourceId. Extra fields or oversized claim sets fail the contract rather than being interpreted as instructions. This is a small schema and domain check, not execution of generated code.
Treat verifier output as fallible
A tool can time out, return stale data or use the wrong scope. Keep tool failure separate from unsupported evidence. If verification calls can recurse or retry, apply a shared budget and preserve their trace.
A second model may share errors with the generator. Calibrate it with adjudicated cases, including believable false answers and known-source wrong claims. Never turn the verifier into another unbounded agent loop.
Keep execution narrow
The teaching host exposes only readPlan and completePlan. It has no eval, shell, generic SQL or arbitrary URL fetch tool. Production compilation or calculations need their own enforced resource/filesystem/network boundaries.
Use the existing Java programs as bounded reference code. Do not execute a generated package-install command solely because the model named a dependency; verify package identity and source independently.
Try it
// Closed-world fact fixtures only. Equality of structured facts is NOT an NLI judge.const object = value => value !== null && typeof value === 'object' && !Array.isArray(value);export function authorizedSources(sources, scope, now) { if (!object(scope) || typeof scope.tenant !== 'string' || typeof scope.user !== 'string' || !Number.isFinite(now)) throw new Error('Invalid trusted scope/time'); return sources.filter(source => source.tenant === scope.tenant && source.approved === true && !source.deleted && source.expiresAt > now && source.readers.includes(scope.user));}export function verifyClaims(claims, sources, scope, now) { if (!Array.isArray(claims) || claims.length > 20) throw new Error('Invalid claims'); const evidence = authorizedSources(sources, scope, now); return claims.map(claim => { if (!object(claim) || Object.keys(claim).sort().join(',') !== 'key,sourceId,value' || ![claim.key,claim.sourceId,claim.value].every(value => typeof value === 'string' && value.length > 0 && value.length <= 200)) throw new Error('Invalid structured claim'); const source = evidence.find(item => item.id === claim.sourceId); const value = source?.facts[claim.key]; return { ...claim, label: value === undefined ? 'INSUFFICIENT_EVIDENCE' : value === claim.value ? 'SUPPORTED' : 'CONTRADICTED' }; });}export function answerPolicy(claims, sources, scope, now) { const labels = verifyClaims(claims,sources,scope,now); return { status:labels.length > 0 && labels.every(item => item.label === 'SUPPORTED') ? 'ANSWER' : 'ABSTAIN', claims:labels };}export function retrievalRecall(relevantIds, retrievedIds) { if (!relevantIds.length) return null; return [...new Set(relevantIds)].filter(id => retrievedIds.includes(id)).length / new Set(relevantIds).size;}export function judgeAgreement(human, judge) { if (human.length !== judge.length) throw new Error('Unpaired annotations'); return human.length ? human.filter((label,index) => label === judge[index]).length / human.length : null;}Run npm run examples:security and npm run eval:security. This source is a deterministic teaching fixture; it does not prove live model safety, NLI, production auth or OS/network isolation.
Interview questions
Is asking the generator again independent verification?
The fixture verifier accepts only key, value and sourceId. Extra fields or oversized claim sets fail the contract rather than being interpreted as instructions. This is a small schema and domain check, not execution of generated code.
Can a verification tool be wrong?
A second model may share errors with the generator. Calibrate it with adjudicated cases, including believable false answers and known-source wrong claims. Never turn the verifier into another unbounded agent loop.
Why avoid a generic shell tool?
Use the existing Java programs as bounded reference code. Do not execute a generated package-install command solely because the model named a dependency; verify package identity and source independently.
Practice
Extend one negative scenario and its authorized positive counterexample for Verification Tools & Structured Answers.
Check your solution
- State the trusted input and effect boundary.
- Assert the expected status and observed effect.
- Report coverage and limitations without claiming production readiness.
Official references
Continue learning
Category sequence
AI Reliability & Hallucinations
Lesson 6 / 10
Was this lesson useful?
Change notes: 2026-10-31: security/reliability curriculum and source-bound fixture.