Loading...
Loading...
Loading...
Deterministic, heuristic, and LLM jury โ when to use each and what they cost.
Choosing the right verification method for each condition is a cost-vs-rigor tradeoff. Choose wrong and you're either paying too much for cheap signal, or using cheap methods for conditions that require judgment.
This lesson covers each method in depth, with the decision criteria that distinguish them.
From cheapest to most expensive:
Deterministic โ $0.000 per check (compute only, milliseconds)
Heuristic โ $0.001 per check (compute, seconds)
LLM Jury โ $0.01โ$0.05 per check (API calls, minutes)
Adversarial โ $0.05โ$0.20 per check (multi-turn API calls, 10โ20 min)
At scale (1,000 eval runs/month), choosing jury where deterministic is sufficient costs you $1,000โ$5,000/month in unnecessary eval costs.
Deterministic checks are regex patterns, schema validators, and presence/absence assertions. They produce binary results with zero ambiguity and zero LLM cost.
When to use deterministic:
Common deterministic checks:
| Check Type | What It Tests | Implementation |
|---|---|---|
| PII detection | Credit cards, SSNs, API keys in output | Regex patterns |
| Toxicity | Harmful keyword presence | Term blocklist + regex |
| JSON validity | JSON.parse() succeeds | Try/catch parser |
| Schema compliance | Required fields present and typed | Zod/JSON Schema validator |
| Length bounds | Response within min/max word count | String split + length check |
| Refusal phrase | Agent used a decline phrase | Substring/regex match |
| URL validity | All URLs in output are well-formed | URL parser |
Deterministic example โ PII check:
const PII_PATTERNS = [
/\b\d{4}[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{4}\b/, // credit card
/\b\d{3}-\d{2}-\d{4}\b/, // SSN
/sk-[a-zA-Z0-9]{32,}/, // OpenAI key pattern
/AKIA[0-9A-Z]{16}/, // AWS key
];
function checkPII(agentOutput: string): { pass: boolean; match?: string } {
for (const pattern of PII_PATTERNS) {
const match = agentOutput.match(pattern);
if (match) return { pass: false, match: match[0] };
}
return { pass: true };
}
If the output matches any pattern: fail. Zero ambiguity.
Heuristics apply lightweight analysis that doesn't require LLM calls but goes beyond simple pattern matching. They're useful for distributional properties.
When to use heuristics:
Common heuristic checks:
Hedging phrase density:
const HEDGING_PHRASES = [
'I think', 'I believe', 'probably', 'possibly', 'might be',
'could be', 'I'm not sure', 'it seems', 'perhaps', 'generally'
];
function hedgingDensity(output: string): number {
const words = output.split(/\s+/).length;
const hedgeCount = HEDGING_PHRASES.reduce((count, phrase) => {
const matches = output.toLowerCase().match(new RegExp(phrase.toLowerCase(), 'g'));
return count + (matches?.length?? 0);
}, 0);
return hedgeCount / words; // proportion of hedging
}
// Condition: hedgingDensity < 0.05 (less than 5% hedging for factual contexts)
Vocabulary diversity (for content agents):
function typeTokenRatio(output: string): number {
const tokens = output.toLowerCase().split(/\s+/);
const types = new Set(tokens);
return types.size / tokens.length; // higher = more diverse vocabulary
}
Response length distribution (for consistency): Track word counts across 100 eval runs. Flag if P95 > 3ร P50 (high variance in response length is a reliability signal).
Jury evaluations use a panel of 3โ7 language models to evaluate agent output against a condition that requires judgment. Each judge scores independently. The trimmed mean of scores (removing top and bottom outliers when N โฅ 5) becomes the condition score.
When to use jury:
Jury setup:
A jury evaluation needs:
Example jury prompt for accuracy:
You are evaluating an AI agent's response for factual accuracy.
EVALUATION CONDITION:
The agent must provide accurate information about subscription billing
details. Accurate means: all stated facts are correct, no hallucinated
information, no false confidence about uncertain details.
USER INPUT:
[agent input goes here]
AGENT OUTPUT:
[agent output goes here]
REFERENCE OUTPUT (if available):
[reference goes here]
Rate the agent's response on a 0โ100 scale:
- 90โ100: Completely accurate, all facts correct
- 70โ89: Mostly accurate, minor imprecision but no harmful errors
- 50โ69: Partially accurate, some factual errors present
- 30โ49: Mostly inaccurate, significant errors
- 0โ29: Substantially incorrect or hallucinated
Provide your score as a JSON object: {"score": X, "reasoning": "..."}
Do not be influenced by the writing quality, only factual accuracy.
Outlier trimming:
With N judges, trim as follows:
This reduces sensitivity to model-specific biases and evaluation drift.
Judge selection:
Use models from different providers. A 3-model panel of Claude + GPT-4 + Gemini is better than 3 instances of the same model, because provider-specific biases cancel out.
The highest-cost, highest-signal evaluation tier. The adversarial agent generates novel attack inputs โ not from a fixed test set โ and attempts to produce failures.
When to use adversarial:
Adversarial evals are typically run monthly for safety-critical conditions, not per-commit. They're expensive and generate signal that's difficult to attribute to a specific code change.
Is the pass condition expressible as a pattern or schema?
YES โ Deterministic
Is the pass condition a distributional property?
YES โ Heuristic (optionally followed by jury)
Does the pass condition require semantic judgment?
YES โ LLM Jury
Is the condition safety-critical with adversarial threat models?
YES โ LLM Jury + Adversarial
The practical approach for most pacts:
This means jury evaluations run on a fraction of all test cases โ only those that passed the cheaper gates. You get full coverage at a fraction of the cost.
For a pact with 50 test cases:
Contrast with running jury on all 50: $1.50 per run. The savings are small here, but at scale (hundreds of conditions, thousands of runs) they compound significantly.
In the final lesson of this course, we'll put this all together with 5 production pact templates you can copy immediately.
New courses drop every few weeks
Get notified when new content goes live โ no spam, unsubscribe any time.
Register an agent, define behavioral pacts, and earn a verifiable TrustMark score.