Skip to content

    Forward Deployed Engineer

    Patterns: Extract, Route and Explain

    Three AI design patterns for understanding a request: structured extraction, classification and routing, and a deterministic filter with a model that explains.

    By Published 8 min read

    • fde
    • solution-architect
    • patterns
    • structured-output
    • routing
    Share

    This lesson is part of AI Solution Architect: Design Method and Patterns. Enroll for free, then sign in, to read it in full.

    What you'll learn: three patterns for turning a request into something a system can act on (structured extraction, classification and routing, and a deterministic filter plus a model that only explains): when to use each, how it fails, how to evaluate it and what it costs.

    At a glance

    Figure 1. Where the three patterns sit in the Order and Policy Assistant

    Extract, route and explain in the Order and Policy AssistantClient app to Orchestrator (asks); Orchestrator to Order system (fetch order); Orchestrator to Model gateway (facts only); Orchestrator to Retriever (policy question)Client app: agent asksClient appagent asksOrchestrator: 1 extract, 2 routeOrchestrator1 extract, 2routeOrder system: 3 filter in codeOrder system3 filter in codeModel gateway: 3 explain onlyModel gateway3 explain onlyRetriever: next pageRetrievernext pageasksfetch orderfacts onlypolicy question

    How to read this: the Orchestrator extracts fields and picks a route; the order route fetches facts in code and sends only those to the model.

    • Extraction turns free text into fields; a field stays empty when the text is silent.
    • Routing sends one input to one of a few handlers; include "other" and "unsure".
    • Filter plus explain keeps facts in code; the model only words them.

    Scenario

    Composite scenario, not a real company. At Lumen Industrial Supply, a fictional distributor, an agent types: "Can the customer still change the address on order 48213?" The assistant must find the order number and intent, fetch the status, apply a policy and explain.

    What you will be able to do

    • Choose between extraction, routing and filter plus explain for a requirement.
    • Say how each pattern fails and how to measure it.
    • Design route labels with "other" and "unsure".

    Prerequisites

    Core ideas

    Pick a pattern from the requirement

    Figure 2. Which understanding pattern fits

    flowchart TD accTitle: Choosing an understanding pattern accDescr: Start with the input. If free text must become fields, use structured extraction. If one input must reach one of several handlers, use classification and routing. If the answer is a fact code can fetch, use a deterministic filter plus explanation. If none apply, use plain code or the answer and act patterns. A["Input from a user"] --> B{"Free text must become fields?"} B -- yes --> E["Structured extraction"] B -- no --> C{"One input, several handlers?"} C -- yes --> R["Classification and routing"] C -- no --> D{"Answer is a fact code can fetch?"} D -- yes --> F["Deterministic filter plus explanation"] D -- no --> N["Plain code, or answer and act patterns"]

    How to read this: ask the questions in order.

    Extraction Routing Filter plus explain
    Model does Reads text into fields Picks one label Words the facts
    Main risk Invented values Wrong label Facts altered
    Check with Field match Confusion table Reply equals facts

    Pattern 1: Structured extraction

    • When to use: free text must become known fields.
    • When not to: the data already arrives structured, or no fixed schema fits.
    • Structure: the "extract" step in the Orchestrator of Figure 1.
    • Failure modes: an invented value for a missing field; a value from the wrong sentence.
    • How to evaluate: hand-label real messages; exact match per field; count invented values.
    • Cost profile: one short call; retries add calls.
    • Minimal build: a schema with optional fields, "leave empty if unstated", a validator, one retry, then a clear error (Structured outputs).
    • Used in the Order and Policy Assistant: yes: order id and question type, with the id checked against the order system.

    Pattern 2: Classification and routing

    • When to use: one entry point, a few handlers, distinct categories.
    • When not to: one handler only, labels humans disagree on, or a button or keyword rule works as well.
    • Structure: the "route" step in the Orchestrator of Figure 1.
    • Failure modes: a confident wrong label; real cases missing from the label set.
    • How to evaluate: a confusion table on labelled messages, weighting costly errors such as a combined question sent down the order-only route; track the "unsure" share.
    • Cost profile: one short call, or none if rules decide (routing policies).
    • Minimal build: three to five labels including "other" and "unsure"; the classifier returns only the label; "unsure" asks a question or goes to a person; log every label.
    • Used in the Order and Policy Assistant: yes, with labels order, policy, both and other.

    Pattern 3: Deterministic filter plus explanation

    • When to use: the answer is a fact or shortlist code can fetch or compute exactly, and people need it in plain words.
    • When not to: the explanation needs facts code did not fetch, or the field alone will do.
    • Structure: the Order system to Model gateway path in Figure 1.
    • Failure modes: the model adds a fact or rewords a number wrongly; code sends too much (personal data) into the prompt.
    • How to evaluate: code checks every number, id and status in the reply against the fetched value; a person reads a sample.
    • Cost profile: one call with a small input, because only filtered facts go in.
    • Minimal build: code fetches only the needed fields; the instruction says to explain only those; a check compares reply and facts; on a mismatch, show the facts alone.
    • Used in the Order and Policy Assistant: yes, for order status.

    In the interview: "When would you not use a model?" A strong answer names what code does exactly (fetch, filter, dates, totals) and where a model helps: reading and wording text.

    Worked example

    Assumptions: illustrative order 48213, status allocated; the delivery date is in the order system.

    Agent message Extract Route Code does Model does
    "Can the customer still change the address on order 48213?" order 48213, change address both Fetch status allocated Explain with P-ORD-04 cited
    "Opened pump delivered 20 days ago, can they return it?" return, opened, 20 days policy Compute days since delivery Explain P-RET-01 v3 (30 days, 15 percent fee if opened and not defective)
    "What is a good lunch place?" nothing found other Fixed out-of-scope message Nothing

    Spot the flaw. A team gives the model the delivery date and today's date and asks: "Is this order inside the return window? Answer yes or no, then explain." What is the flaw?

    Answer

    Counting days and comparing with 30 is exact, so it belongs in code; a model can miscount. Give the model the result to explain.

    Decision exercise. An agent pastes a customer email. The assistant must pull out the order id and complaint, route returns and status questions differently, and explain the status. Choose and justify:

    • (A) one large prompt does everything.
    • (B) extract, route, fetch in code, explain.
    • (C) classify only; the agent copies the fields.
    Model answer

    Choose B. Each pattern does one small job and is tested alone: field match, confusion table, facts check. A mixes three failure modes in one unmeasurable reply. C is safe but saves no time.

    Practice task

    Start your pattern shortlist (artifact 2, first part): three rows for the Order and Policy Assistant, each with yes or no, one sentence of reason and how you would evaluate it. Then list the fields extraction returns.

    Decide first, then reveal.

    Understand patterns: pick the safe behaviour (interactive when JavaScript is on)

    A message reads: 'problem with the pump order'. The classifier cannot tell which label fits.

    • Pick the likelier label and answer
    • Ask the agent one clarifying question, or hand the contact back
    • Use the 'both' route so the agent gets two answers
    Answer

    Ask the agent one clarifying question, or hand the contact back. Unsure costs a question but never gives a wrong answer. 'Both' is for questions needing an order status and a policy.

    An agent writes: 'Customer wants to return the pump.' No order number. What should extraction return for the order id?

    • Empty, so the agent can be asked for it
    • The last order number it saw
    • A placeholder such as 00000 to satisfy the schema
    Answer

    Empty, so the agent can be asked for it. A field stays empty when the text is silent. A required field pushes the model to invent a value.

    The reply to an order-status question says 'shipped'. The order system says `allocated`. What does the code do?

    • Send the reply and log a warning
    • Ask the model again until the reply matches
    • Show the facts alone
    Answer

    Show the facts alone. On a mismatch code shows the facts alone. Sending a reply that failed its check is the mistake.

    Exercise

    Design the route labels for the 9,600 contacts (5,280 orders, 3,360 policies, 960 other; illustrative): each label, what its handler does and what happens when the classifier is unsure.

    Acceptance criteria: three or more labels plus "unsure"; a combined question has a defined route; an unsure message never gets a guessed answer. Done when a reviewer can take any contact type and name its handler.

    Hint 1: the combined question

    It needs an order status and a policy. Own label, or two handlers?

    Hint 2: what unsure does

    Ask the agent one clarifying question, or hand the contact back.

    Common mistakes

    • Routing with a model when a button or keyword rule would do.
    • No "other" or "unsure" label, so odd messages get confident wrong answers.
    • Letting the model guess a missing field.
    • Sending the whole order record, personal data included.

    Knowledge check

    1. Why must an extraction schema allow empty fields?

    If every field is required, the model invents a value to satisfy the schema. An empty field is honest; the agent can be asked.

    2. Why include "unsure" as a route label?

    Without it an ambiguous message lands in a wrong bucket and is answered confidently. "Unsure" costs one question.

    3. In filter plus explain, why does code check the reply against the facts?

    The model may reword a number or add a fact. The facts came from code, so code can compare them with the reply and fall back to the facts alone.

    4. What is each pattern's main failure, and how is each measured?

    Extraction invents values (field match), routing picks a wrong label (confusion table) and filter plus explain alters facts (reply compared with facts).

    5. When would you choose a rule over a model classifier for routing?

    When the signal is explicit, such as a button or keyword: a rule is free and predictable. Use a model when one intent has many wordings that rules miss.

    You can now

    • Add the first part of your pattern shortlist to your design pack.
    • Choose among extraction, routing and filter plus explain.
    • Name each pattern's failure mode and how to measure it.
    • Design route labels with "other" and "unsure".

    Further reading

    Last verified: 2026-11-03

    Next

    Patterns: retrieval, hybrid search, documents

    Enroll to keep reading

    Lesson 2 of 6 · AI Solution Architect: Design Method and Patterns

    Three AI design patterns for understanding a request: structured extraction, classification and routing, and a deterministic filter with a model that explains.

    In the rest of this lesson

    • Practice task
    • Exercise
    • Common mistakes
    • Knowledge check
    • You can now
    • Further reading

    Enrolling is free. It unlocks every lesson in AI Solution Architect: Design Method and Patterns, tracks your progress across devices and keeps your quiz scores. The newsletter is optional.

    Ask about this article

    Get answers grounded in this post. AI-generated — based on this article, and may be imperfect.

    Scaled AI Weekly

    Enjoyed this? Get more like it every Monday.

    Real architecture decisions, LLMOps patterns that survive production, and engineering leadership advice — from 12+ years of building at enterprise scale. Free. No spam. Unsubscribe anytime.

    Get new articles by email

    Free. We email a confirmation link first, and you can unsubscribe from any email.

    Join engineers building production AI systems

    Comments