Scaling AI Applications with LLMs: Dynamic Context Injection and Few-Shot Learning for Order Processing

choco · Tech · 2025 · source Agentic: no · promotional bias: low · source-backed · extracted with prompt 0.5.6 (schema v2)

Generated from extraction.json — do not edit by hand. Every claim cites verbatim source evidence; stated means the quote directly asserts the claim, implied means it supports it indirectly.

Problem

Domain: Food supply-chain order processing

Choco needed to improve LLM-based order extraction across heterogeneous restaurant order formats, including shorthand texts, semi-structured PDFs, and voicemail transcripts, while avoiding brittle fine-tuning cycles and enabling customer-success teams to feed new examples back into the system.

Constraints:

Architecture

Choco built an in-context learning system that labels common order formats, retrieves relevant examples at inference, injects distributor and customer context, and lets customer-success teams add new labels from the order inspection tool. Embedding-based semantic retrieval supplements metadata matching, while dynamic context injection provides order history, distributor assortment, and product catalog hints for transcription correction and extraction.

Diagram confidence: explicit (topology described by the source).

flowchart LR
  A["Incoming orders"] --> B["Information extraction step"]
  C["Customer success labeling interface"] --> D["Labeled examples store"]
  D --> E["Example retrieval system"]
  E --> B
  F["Dynamic context injector"] --> B
  B --> G["Structured order output"]
  G --> C
Drag to pan · scroll or use +/− to zoom · reconstructed from the source's described component topology

Components

Component Role Interacts with
Incoming orders Text messages, PDF orders, emails, and voicemail transcripts from restaurants. Information extraction step
Information extraction step LLM component that extracts products, quantities, and restaurant details into structured JSON. Example retrieval system, Dynamic context injector, Structured order output
Customer success labeling interface Tool for annotating orders and adding new labels when formats or failure modes appear. Labeled examples store
Labeled examples store Repository of distributor/customer-specific labeled order formats used for few-shot prompting, evaluation, and future fine-tuning. Example retrieval system
Example retrieval system Metadata and embedding-based retrieval layer that selects relevant labeled examples for each order. Information extraction step
Dynamic context injector Prompt assembly layer adding distributor category, recent order history, popular products, and instructions for using context. Information extraction step
Structured order output JSON output consumed by downstream order-processing tasks. Customer success labeling interface

Data flow

Incoming text, PDF, or voicemail orders enter an information-extraction step that converts product names, quantities, and restaurant details into structured JSON. The system retrieves labeled examples by metadata and semantic similarity, injects recent order history and distributor context, and passes the enriched prompt to the LLM. Customer-success annotations and corrections become new labels, evaluation data, and future retrieval context.

3 supporting quotes
“Each order goes through a different processing step that extracts key details–such as product names, quantities and restaurant name– and converts them into a structured JSON format required for downstream tasks.”article, stated
“At inference, we compute the embedding of the incoming order and perform a semantic search to retrieve labeled examples with similar structure.”article, stated
“we dynamically injected additional context: * The distributor’s assortment category (e.g., “This is a fish distributor”), stored as metadata.”article, stated

Why this architecture

Choco chose prompt-based in-context learning and dynamic context injection because they support targeted, reversible improvements without retraining every time a schema or failure mode changes. Semantic retrieval handles layout similarity that metadata alone misses, and customer-success labeling turns operational corrections into reusable examples.

3 supporting quotes
“Prompt-based improvement techniques provide a structured and predictable way to improve system performance while avoiding the risks of fine-tuning, which can introduce unintended regressions.”article, stated
“By dynamically injecting relevant context into prompts, we can make targeted, surgical improvements and maintain control over when, how, and what context is added.”article, stated
“While few-shot learning generally improves information extraction, its effectiveness depends on retrieving the right labeled examples for the right incoming orders.”article, stated

Models used: LLMs · ASR models · embedding models · smaller models · fine-tuned models

Scale

Alternatives considered (roads not taken)

Metadata-only example matching

Rejected because: Metadata matching breaks down with layout variation, ambiguous senders, and unseen formats, so Choco added semantic retrieval.

“Our primary approach has been metadata-based matching. While this method works well in many cases, it has its limitation when faced with variations in order layouts, ambiguous sender information, or unseen formats.”article, stated

Generic catch-all transcription correction prompt

Rejected because: The generic prompt improved some transcriptions but struggled with brand names, uncommon products, and colloquial ordering language.

“this generic “catch-all” prompt initially led to performance improvements but struggled with correcting brand names and uncommon products.”article, stated

Fine-tuning as the primary improvement path

Rejected because: Fine-tuning is slower, less precise, and requires retraining when output schemas change.

“Fine-tuning, on the other hand, is often slower and less precise. Adding examples to a training dataset does not guarantee a model will generalize correctly or prevent similar mistakes in the future.”article, stated

Patterns

context-engineering (context)

Choco dynamically injects distributor categories, prior orders, popular products, and instructions for how the LLM should use that context.

“Our engineering efforts focused on building systems that continuously generate and inject relevant dynamically labeled examples, along with personalized, contextual information”article, stated
“Context-for-context is important! We also explain to the LLM what to do with the information provided:”article, stated

rag-retrieval (retrieval)

Choco indexes labeled examples as embeddings and retrieves similar order formats at inference so the prompt receives relevant few-shot examples.

“By leveraging an embeddings-based retrieval system, we index labeled examples as vector representations in a database. At inference, we compute the embedding of the incoming order and perform a semantic search to retrieve labeled examples with similar structure.”article, stated
“If the retrieved candidates meet a similarity threshold, they are used as few-shot examples in the prompt, improving adaptability without requiring manual labeling for every possible format.”article, stated

human-in-the-loop-gate (governance)

Customer-success staff annotate orders and add labels when new formats or failure modes appear, feeding human expertise into the system.

“we developed a simple interface that enables our customer success teams to annotate orders directly within our order inspection tool.”article, stated
“When a new order format or failure mode is identified, we can immediately add a new label, ensuring our system continuously improves its information extraction capabilities.”article, stated

structured-output-contract (data)

The extraction task converts heterogeneous orders into structured JSON required by downstream processing.

“converts them into a structured JSON format required for downstream tasks.”article, stated

eval-driven-development (evaluation)

Choco treats labeled examples as evaluation data and uses operational labels/corrections to refine LLM components.

“The labeled examples we generate for few-shot learning hold immense value beyond the applications we outlined in this article.”article, stated
“2. A dataset for evaluating and refining our LLM components.”article, stated

Tradeoffs

Prompt-based improvement versus fine-tuning first

Chose in-context learning and dynamic context injection first over fine-tuning as the primary improvement mechanism.

Rationale: Prompt methods let Choco make targeted changes, keep control over inserted context, avoid regressions, and switch models as newer LLMs appear.

“we can make targeted, surgical improvements and maintain control over when, how, and what context is added.”article, stated
“Avoiding dependence on a single custom LLM has also given us the freedom to quickly experiment and integrate the latest LLMs into our system”article, stated

Example retrieval strategy

Chose semantic retrieval over labeled example embeddings over metadata-based matching alone.

Rationale: Embedding retrieval can match structurally similar orders even when metadata or sender information differs.

“Order formats often share structural similarities. For example, PDF orders from different restaurants that use the same tool may have the same layout.”article, stated
“If the retrieved candidates meet a similarity threshold, they are used as few-shot examples in the prompt, improving adaptability without requiring manual labeling for every possible format.”article, stated

Human expertise in the loop

Chose customer-success annotation interfaces over ML-only ownership of new labels.

Rationale: Customer-success teams can label real order formats and failure modes directly, reducing the need for deep ML expertise.

“enables our customer success teams to annotate orders directly within our order inspection tool.”article, stated
“Additionally, it creates opportunities to build user-friendly interfaces for our Customer Success team, enabling them to independently contribute to system improvements without deep ML expertise.”article, stated

Gotchas (what bit them)

Few-shot quality depends on retrieving the right examples.

Root cause: Metadata matching alone misses layout variations, ambiguous senders, and unseen formats.

Resolution: Choco added embedding-based semantic retrieval over labeled examples.

“While few-shot learning generally improves information extraction, its effectiveness depends on retrieving the right labeled examples for the right incoming orders. Our primary approach has been metadata-based matching.”article, stated
“To address these limitations, we experimented with semantic retrieval using embeddings. Order formats often share structural similarities.”article, stated

Generic prompts fail on domain-specific product names.

Root cause: Restaurant orders use uncommon products, brand names, and colloquial terms such as bottle-cap color names.

Resolution: Inject distributor assortment, recent order history, popular products, and guidance on how to use the context.

“restaurants often order in a colloquial manner—for example, in the UK, 'blue milk' refers to milk identified by its bottle cap or carton color.”article, stated
“To capture further improvements, we dynamically injected additional context:”article, stated

Fine-tuning slows targeted fixes and schema changes.

Root cause: Adding training examples does not guarantee the exact generalization needed, and output schema changes require retraining.

Resolution: Prioritize prompt-based in-context methods for fast, surgical improvements while keeping fine-tuning complementary.

“Adding examples to a training dataset does not guarantee a model will generalize correctly or prevent similar mistakes in the future.”article, stated
“Additionally, changes in output schema require retraining, slowing deployment.”article, stated

Evaluation

Choco evaluates and improves components through labeled examples, customer-success annotations, corrections from failure modes, semantic retrieval feasibility tests, and datasets that support evaluation and refinement of LLM components.

Metrics: Information extraction accuracy · Similarity threshold for retrieved examples · New order formats and failure modes labeled · Mistranscription correction quality · Fine-tuning and evaluation dataset growth

“Early experiments proved the feasibility of this approach.”article, stated
“2. A dataset for evaluating and refining our LLM components.”article, stated

Outcomes

The article does not disclose order volume, but it describes production handling across multiple order modalities, distributor/customer-specific formats, recent-weeks order history, and reusable labels for fine-tuning, evaluation, new-label creation, and autonomous error judging.

“Scaling our system hinges on these labeling strategies, which not only enhance reliability but also ensure continuous improvement and adaptability.”article, stated
“Moving towards fully autonomous AI systems is not about eliminating human involvement. It's about designing systems that continuously learn from human expertise while minimizing manual intervention.”article, stated