Evaluate and operate / Lesson 22 of 24

Apply the patterns

Map all eighteen official cookbook patterns to retrieval, selection, verification, extraction, routing, and scoring problems.

After this moduleYou can choose and compose a cookbook pattern while keeping deterministic invariants visible.

Search, retrieve, and recover structure

The previous lessons established evaluation and operating constraints. This lesson uses them to choose among the official cookbook patterns. pattern: a reusable division of responsibility among retrieval, semantic judgment, deterministic policy, and visible product behavior is more useful than copying a demo threshold.

Patterns 1 and 2 are Noul self-consistency and Choice self-consistency: repeat frozen cases to observe probability and label movement, then test whether a review band stabilizes product actions. Pattern 3 is parallel questions: send independent judgments over shared state together, reducing repeated state and round trips while still paying for question tokens.

Self-consistency is a diagnostic pattern, not a request to vote away every uncertainty. Retain every run, distribution, changed irrelevant field, and resulting action. If repeated answers cross a policy boundary, either the question, threshold, or model version needs evaluation. Parallel batching should preserve identical question meanings; it does not allow one question to read another result. When a branch truly depends on an earlier answer, use a second request with newly retrieved state.

Pattern 4 is reranking: deterministic search retrieves candidates, one Noul per candidate judges relevance, and code sorts. Retrieval coverage is a separate metric because omitted evidence cannot be recovered. Pattern 5, line-by-line search, combines a Choice over line IDs with a Noul asking whether any answer exists, separating relative rank from absolute suitability. Pattern 6, structure recovery, asks Nouls about adjacent line breaks, stitches blocks in code, then uses Choices to label newly created blocks. It reconstructs rather than generates source text.

const candidates = bm25(query).slice(0, 30);
const state = {
  query,
  candidates: candidates.map(({ id, text }) => ({ id, text })),
};
const questions = Object.fromEntries(
  candidates.map((candidate, index) => [
    `relevant_${candidate.id}`,
    {
      type: "noul",
      instructions: `Does \`candidates[${index}].text\` directly answer \`query\`? Judge only candidate ${candidate.id}.`,
    },
  ]),
);
Trace this example from input to result
01

Customer choice

A support agent searches a versioned policy corpus.

02

Request or event

The query retrieves a bounded set of versioned policy passages.

03

Backend behavior

Jev judges relevance and contradiction while code preserves source text, provenance, and no-answer behavior.

04

Customer sees

The agent sees ranked evidence or an explicit no-answer result.

05

Diagnostic reasoning

Check retrieval coverage before judging the reranker; a perfect selector cannot recover an omitted passage.

Select tools, skills, entities, and evidence

Pattern 7 is function calling: a Choice selects among ordinary typed functions, additional bounded questions fill enum-like arguments, and code validates authorization. Open text arguments need extraction or generation. Pattern 8 is skill suggestion: rank a large skill list, independently ask whether any skill is needed, fetch details for top candidates, then allow rejection. This is staged because later state depends on the first result.

Pattern 9 is knowledge-graph entity alignment: a Score's ordered levels correspond to keep separate, curate, or merge, while companion Nouls identify field disagreements. Code still validates identifiers and performs the merge. Pattern 10 is RAG passage classification: separate Nouls judge relevance, usable evidence, contradiction, and embedded instructions; code builds evidence, conflict, and drop groups before generation.

Pattern 11 is citation checking: exact string matching first catches fabricated quotations, then a Choice labels surviving context as support, contradiction, or unrelated. Uncertain verdicts enter review. Pattern 12 is LLM guardrails: hazard Nouls and a harm Score inspect inputs and outputs, while policy maps the same signals to pass, review, block, or crisis handling. It does not prove adversarial robustness.

Customer seesApplication doesJev returns
A suggested tool that still asks permissionFilters allowed tools and validates arguments and identityRelative tool choice and bounded risk judgments
A cited answer with review flagsChecks exact quotes, preserves sources, and routes uncertaintySupport, contradiction, or unrelated distribution
Applied diagnosis

A tool wins but cannot perform the request

choice=reset_password · account identity unverified

The Choice answered relative fit; it did not authorize execution. Deterministic capability and identity checks must filter or block the tool. Add a no-match path and review outcome, then test unsupported and unauthorized requests as separate synthetic fixtures.

Extract, classify, and build features

Pattern 13 is a structured data extraction (SDE) cascade: a cheaper generator extracts fields, Jev asks failure-signal Nouls about each field, and suspicious records escalate to a stronger reasoner or person. Jev verifies bounded claims rather than generating values. Pattern 14 is date extraction: Choices identify date kind and named components; code resolves relative dates, validates calendars, and compares values.

Pattern 15 is pre-parsed value extraction: regex or a parser intentionally over-finds email, phone, and amount candidates; Jev selects the intended source span and attributes; code copies and normalizes it. Candidate recall is the hard boundary. Pattern 16 is hierarchical classification: Choices traverse a pinned taxonomy. Greedy search keeps one path; beam search retains several and ranks with application math. The path score is not a calibrated leaf probability.

Pattern 17 is autoresearch feature discovery: a generator proposes narrow Noul and Score features, Jev evaluates them, and held-out outcomes determine which features survive in a classical model. This requires leakage control and stable labels. Pattern 18 is classification using confidence: a Choice predicts a fine class, then code returns a broader parent class or review when confidence is low. The threshold and hierarchy must be evaluated on the target distribution.

Feature discovery is especially vulnerable to overfitting because many proposed questions compete for the same limited outcomes. Keep a final untouched test set and record every search round. Hierarchical broadening has a different risk: a confident parent may be useful even when a leaf is uncertain, but only if the taxonomy version and parent mapping are deterministic. Never describe the cookbook path score as the probability that the leaf is correct.

function normalizeSelectedAmount(candidates: Candidate[], selectedId: string) {
  const candidate = candidates.find((item) => item.id === selectedId);
  if (!candidate) throw new Error("Selected candidate is absent");
  return parseCurrency(candidate.exactText); // code copies and parses source
}
Dig deeperCompose patterns without collapsing boundaries

A support assistant might retrieve passages, classify them for evidence and contradiction, verify citations, select a tool, and gate its action. Keep every intermediate artifact and question version. Do not turn the composition into one broad "is this response good?" judgment: that loses the ability to locate missing retrieval, unsupported citation, unsafe tool choice, or policy failure. Combine independent questions in one request only when they share state and do not depend on one another's answers.

Choose a pattern from the failure you can tolerate

Begin with what the customer sees. If they need a source value, select and copy rather than generate. If they need ranked evidence, retrieve broadly and rerank. If they need a reversible route, use Choice plus no-match and review. If they need an exact date or amount, extract bounded components and let code calculate. If a generator already exists, use Jev as a narrow verifier and escalate suspicious cases.

Across all eighteen patterns, preserve deterministic invariants: candidate coverage, permissions, arithmetic, source fidelity, idempotency, and current state. Evaluate answer quality and downstream action separately. Treat cookbook thresholds and measurements as worked examples, and label your own fixtures synthetic.

A pattern review should finish with a deletion test: what breaks if the Jev judgment is unavailable? If the entire product loses its source record or permission check, the boundary is too deep. A sound design preserves customer data, provenance, and safe review while losing only the semantic convenience. Also ask whether a simpler parser, lookup, or rule already solves the task. Jev earns its place where meaning is genuinely needed and measured.

Saved locally

Map a workflow to patterns

Your answers stay in this browser. Write enough that another engineer could continue the investigation.

Knowledge check

Check your understanding

Select among all eighteen cookbook patterns by the product behavior and failure boundary, then keep retrieval, semantic judgment, policy, and execution independently testable.

Module quiz

0/4 answered

01Why pair line ranking with a no-answer Noul?
02Which pattern extracts an amount without letting Jev invent it?
03When should a second request follow speculative fan-out?
04What remains code-owned in function calling?
Sources and verification notes 24
Official cookbookspublic-contract

All 18 indexed cookbooks were reviewed; measurements remain attributed, dated vendor reports.

Composition patternspublic-contract

Fan-out, confidence-gated routing, composite scoring and intent routing.

Speculative fan-outpublic-contract

Documented composition pattern; application code owns policy, validation and side effects.

Confidence-gated routingpublic-contract

Documented composition pattern; application code owns policy, validation and side effects.

Composite scoringpublic-contract

Documented composition pattern; application code owns policy, validation and side effects.

Intent routingpublic-contract

Documented composition pattern; application code owns policy, validation and side effects.

Self-consistency: noulsobserved

First-party worked example inspected September 18. Workflow and published artifacts were reviewed; thresholds and measurements are dated vendor reports and were not independently reproduced.

Self-consistency: choicesobserved

First-party worked example inspected September 18. Workflow and published artifacts were reviewed; thresholds and measurements are dated vendor reports and were not independently reproduced.

Parallel questionsobserved

First-party worked example inspected September 18. Workflow and published artifacts were reviewed; thresholds and measurements are dated vendor reports and were not independently reproduced.

Re-rankingobserved

First-party worked example inspected September 18. Workflow and published artifacts were reviewed; thresholds and measurements are dated vendor reports and were not independently reproduced.

Line-by-line searchobserved

First-party worked example inspected September 18. Workflow and published artifacts were reviewed; thresholds and measurements are dated vendor reports and were not independently reproduced.

Structure recoveryobserved

First-party worked example inspected September 18. Workflow and published artifacts were reviewed; thresholds and measurements are dated vendor reports and were not independently reproduced.

Function callingobserved

First-party worked example inspected September 18. Workflow and published artifacts were reviewed; thresholds and measurements are dated vendor reports and were not independently reproduced.

Skill suggestionobserved

First-party worked example inspected September 18. Workflow and published artifacts were reviewed; thresholds and measurements are dated vendor reports and were not independently reproduced.

Knowledge graph entity alignmentobserved

First-party worked example inspected September 18. Workflow and published artifacts were reviewed; thresholds and measurements are dated vendor reports and were not independently reproduced.

Classifying RAG passagesobserved

First-party worked example inspected September 18. Workflow and published artifacts were reviewed; thresholds and measurements are dated vendor reports and were not independently reproduced.

Double-checking citationsobserved

First-party worked example inspected September 18. Workflow and published artifacts were reviewed; thresholds and measurements are dated vendor reports and were not independently reproduced.

Guardrails for LLMsobserved

First-party worked example inspected September 18. Workflow and published artifacts were reviewed; thresholds and measurements are dated vendor reports and were not independently reproduced.

SDE cascadeobserved

First-party worked example inspected September 18. Workflow and published artifacts were reviewed; thresholds and measurements are dated vendor reports and were not independently reproduced.

Date extractionobserved

First-party worked example inspected September 18. Workflow and published artifacts were reviewed; thresholds and measurements are dated vendor reports and were not independently reproduced.

Pre-parsed value extractionobserved

First-party worked example inspected September 18. Workflow and published artifacts were reviewed; thresholds and measurements are dated vendor reports and were not independently reproduced.

Hierarchical classificationobserved

First-party worked example inspected September 18. Workflow and published artifacts were reviewed; thresholds and measurements are dated vendor reports and were not independently reproduced.

Autoresearch feature discoveryobserved

First-party worked example inspected September 18. Workflow and published artifacts were reviewed; thresholds and measurements are dated vendor reports and were not independently reproduced.

Classification using confidenceobserved

First-party worked example inspected September 18. Workflow and published artifacts were reviewed; thresholds and measurements are dated vendor reports and were not independently reproduced.

Further learning

Optional references

These resources provide public documentation and examples for readers who want them.

IndexTypeSafe cookbooksDocsUse-case map