Part III · Building and operating AI/Chapter 10 of 20/7 min read

How Models Fit Into a Product

A practical guide to tokens, hallucinations, context rot, structured outputs, tool calling and retrieval mechanics for product decisions.

Reference cards feed through an indexing tray and optical prism module into aligned structured blocks on a workbench.
Reference cards feed through an indexing tray and optical prism module into aligned structured blocks on a workbench.Plate 10
On this page7 sections
  1. 01Tokens and next-token prediction explain why models hallucinate
  2. 02Bigger context windows do not prevent context rot
  3. 03Retrieval brings private and current data into the loop
  4. 04Structured outputs and tool calling bridge models to software
  5. 05Manage variability deliberately
  6. 06Choose the right fix when quality falls short
  7. 07Try it: follow the information

When an AI feature gives a confident, wrong answer, the least helpful response in the room is "the model hallucinated; let's try a smarter one."

Most production AI failures have nothing to do with missing foundation-model intelligence. They come from how text gets tokenised, how context degrades as prompts grow, how retrieval misses the right clause or how probabilistic outputs collide with rigid downstream software.

Product managers do not need to train neural networks to prevent these failures. They do need a clear mental model of what goes into a model, what comes out and where reliability breaks in between.

Tokens and next-token prediction explain why models hallucinate

A large language model does not look up facts in a database. It splits input text into sub-word units called tokens (roughly three-quarters of an English word on average, though code, numbers and non-English languages tokenise less efficiently) and predicts the most probable next token, one token at a time, based on its training weights and whatever sits in the current input.

That single mechanism explains three everyday product behaviours:

  1. Fluency is completely decoupled from truth. A model generates a fabricated policy clause, a fake citation or a plausible-sounding customer name with the exact same grammatical polish as a verified fact. Never equate confident tone with correctness.
  2. Input and output cost and speed behave asymmetrically. Processing input tokens (prefill) runs in parallel and is fast and cheap; generating output tokens happens sequentially one token at a time, making output tokens slower and typically several times more expensive. Long, chatty outputs hurt both latency and unit economics.
  3. Multimodal inputs follow the same constraint. Vision and audio models convert images, PDFs and speech into token equivalents too. High-resolution scans and long audio clips inflate latency and context usage far faster than plain text.

Bigger context windows do not prevent context rot

The context window is the maximum combined size of everything sent to a model in one call (system instructions, tool schemas, conversation history, retrieved documents) plus its generated output.

Marketing numbers for context windows have grown into hundreds of thousands or millions of tokens. In production, treating a giant context window as a dumping ground backfires. As inputs fill with loosely relevant documents, outdated policy versions and long chat histories, model performance degrades sharply, a pattern often called context rot:

  • Important rules buried in the middle of long inputs get missed more often than rules near the start or end.
  • Conflicting passages from old and new documents cause the model to blend rules from both.
  • Every extra token increases time-to-first-token latency and inference cost on every single turn.

Treat context like working memory, not cold storage. Supply only the current, authoritative material required for the active step, strip noise aggressively and test performance on realistic production document lengths rather than tidy three-paragraph samples.

Retrieval brings private and current data into the loop

Because model training data is frozen in the past and never includes your private customer records, products use retrieval-augmented generation (RAG): searching a permitted corpus at runtime and injecting the best-matching passages into the prompt.

FIG 10.1Where Retrieval and Context Break Before the Model
SOURCE DOCSPolicies, tickets,live recordsFAILURE 1Stale / conflictingversions indexedCHUNKINGSplit & indexwith metadataFAILURE 2Clause split fromits exception ruleHYBRID + ACLVector + keyword+ user scopeFAILURE 3Misses exact IDsor leaks tenant dataCONTEXTPrompt + skills+ top passagesFAILURE 4Context rot fromlong noisy historyOUTPUTTyped JSON +verified citationsFAILURE 5Fluent claim notbacked by source
Four failure modes sit upstream of generation. Fixing stale sources, bad chunking or missing permission filters solves most 'hallucinations'.

RAG solves freshness and privacy, while introducing four distinct failure modes that PMs must recognise:

Retrieval layerWhat goes wrong in production
Source hygieneDuplicate, conflicting or outdated documents sit in the index alongside current rules
ChunkingDocuments get sliced arbitrarily by character count, splitting a table header from its rows or an exception clause from its main rule
Search qualityPure semantic (vector) search misses exact SKUs, policy codes and acronyms; pure keyword search misses synonyms. Production systems usually need hybrid search plus reranking
Permission filteringSearch retrieves a restricted document the current user is not authorised to see, leaking private tenant or HR data into the generated answer

Remember one hard truth about citations: a clickable citation only proves the model copied a link from its input; it does not prove the cited passage actually supports the claim. Verify groundedness directly in your evaluation suite.

Structured outputs and tool calling bridge models to software

Free-form prose is useful for humans and terrible for downstream code. Modern AI products rely on two primitives to connect probabilistic models to deterministic systems:

  • Structured outputs (schema enforcement): Constraining the model to return valid JSON matching a strict schema (enums, required fields, explicit "unknown" or "needs_review" states). This eliminates brittle regex parsing and forces the model to declare missing fields explicitly rather than hiding gaps inside smooth paragraphs.
  • Tool calling (function calling): Giving the model typed definitions of external actions (search knowledge base, query account balance, create draft ticket). The model does not execute the tool directly; it emits a structured request naming the tool and arguments, and your application code validates permissions, runs the call and feeds the result back into context.

Tool schemas and field descriptions are part of the product surface. Vague parameter names, overlapping tools or poorly worded error messages cause models to pick the wrong tool or retry blindly in loops.

Manage variability deliberately

Even with identical inputs, language models are non-deterministic by default. Sampling settings like temperature control randomness: lower values make outputs tighter and more repeatable (better for classification, extraction and tool selection); higher values widen variation (useful for brainstorming or creative drafting). Even at temperature zero, floating-point differences and provider batching can produce slight run-to-run variance.

Never judge a workflow on a single lucky run. For reliability-sensitive tasks, run representative test cases multiple times, record the exact model version and configuration, and build deterministic validation around the output.

Choose the right fix when quality falls short

When a workflow underperforms, work down this intervention ladder in order from cheapest and highest-leverage to heaviest:

  1. Fix the context first. Clean stale sources, repair chunking, switch to hybrid search, trim irrelevant history or add two concrete input/output examples. Most "model failures" vanish here.
  2. Tighten the instructions and workflow. Clarify ambiguous edge cases, split one overloaded prompt into two focused steps, enforce a structured output schema or move deterministic checks into code.
  3. Swap or route the model. Benchmark alternative models on your actual eval set across quality, p95 latency and cost, not public leaderboards.
  4. Fine-tune only when simpler levers plateau. Fine-tuning adapts a model's weights on curated training examples. It works well for consistent style, narrow classification or distilling a large model's behaviour into a faster, cheaper one. It is the wrong tool for injecting fast-changing facts or enforcing access controls, and it locks you into maintaining custom datasets every time base models upgrade.

The surrounding architecture that binds these pieces together sits next in The Model Harness and Routing.

Try it: follow the information

Pick one real AI task you work on (for example, answering a customer billing question or summarising a renewal risk). On a single page, sketch four boxes:

  1. The exact user request and who is allowed to see what.
  2. Every source document, database field and rule required to answer accurately.
  3. Where each piece of information comes from, how often it changes and who owns keeping it current.
  4. The two points most likely to fail silently (stale doc, missed chunk, missing permission filter or ambiguous instruction).

Compare your sketch with a real trace alongside an engineer (or work through the trace exercise in The Model Harness and Routing). Nine times out of ten, the highest-leverage product fix shows up in the boxes around the model, not inside it.

Handbook v4.0 · Ch. 10Updated Nov 2026