Advanced Prompt Engineering Techniques for Production LLM Applications

instacart · E-commerce · 2023 · source Agentic: no · promotional bias: low · source-backed · extracted with prompt 0.5.2 (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: Production prompt engineering

Instacart needed prompt techniques that made LLM outputs more reliable for internal productivity tools.

Constraints:

Architecture

Instacart describes an internal productivity-tooling pattern library for GPT-4/GPT-3.5 applications rather than one monolithic app. The architecture wraps an internal OpenAI/LLM proxy and task workflows with prompt techniques: ReAct delegates tool calls to application software, Room for Thought decomposes generation into intermediate steps, Monte Carlo samples several options before finalizing, self-correction asks the model to critique its own output, a classifier endpoint guarantees valid outputs with logit bias, and puppetry pre-fills response form. The system is a production prompt-control layer around internal tools.

Diagram confidence: reconstructed (reconstructed from prose).

flowchart LR
  internal-productivity-tools[Internal productivity tools] --> prompt-technique-library[Prompt technique library]
  internal-productivity-tools --> internal-llm-proxy[Internal LLM proxy]
  prompt-technique-library --> gpt-models[GPT models]
  internal-llm-proxy --> gpt-models
  prompt-technique-library --> react-action-executor[ReAct action executor]
  react-action-executor --> internal-productivity-tools
  prompt-technique-library --> draft-synthesis-loop[Draft synthesis loop]
  draft-synthesis-loop --> gpt-models
  internal-llm-proxy --> classifier-endpoint[Classifier endpoint]
  classifier-endpoint --> gpt-models
  few-shot-examples[Few-shot examples] --> prompt-technique-library
Drag to pan · scroll or use +/− to zoom · reconstructed from the source's described component topology

Components

Component Role Interacts with
Internal productivity tools Instacart employee workflows that use LLMs for writing, PR descriptions, lookup, search, classification, and similar tasks. Prompt technique library, Internal LLM proxy
Prompt technique library Reusable prompt patterns such as ReAct, Room for Thought, Monte Carlo, self-correction, classification, and puppetry. Internal productivity tools, GPT models
Internal LLM proxy Internal OpenAI/LLM proxy that mediates model calls and classification endpoint behavior. Internal productivity tools, GPT models, Classifier endpoint
GPT models GPT-4 and GPT-3.5 models used by the internal applications. Internal LLM proxy, Prompt technique library
ReAct action executor Application software that performs model-requested lookup, search, or calculation actions and re-prompts with results. Prompt technique library, Internal productivity tools
Draft synthesis loop Monte Carlo and self-correction flows that generate options, critique, and consolidate final outputs. Prompt technique library, GPT models
Classifier endpoint Proxy endpoint that constrains output to valid labels and can bias token probabilities. Internal LLM proxy, GPT models
Few-shot examples Prompt examples used to steer output style and expected behavior. Prompt technique library

Data flow

Internal productivity workflows send task prompts through Instacart's LLM proxy to GPT-4 or GPT-3.5. Depending on the task, the prompt may request an outline before final generation, ask the model to call tools that application software executes and feeds back, sample multiple drafts and synthesize a final answer, critique and revise its own output, or route through a classifier endpoint that guarantees valid output.

3 supporting quotes
“all of these prompt techniques have been implemented and used with GPT-4. Some have also been used with GPT-3.5.”article, implied
“Now when the model responds it may use INTERNAL_LOOKUP, GOOGLE_SEARCH, or calculation, and our software will perform the action and re-ask the model to complete the task with the new information. In this way we can build up a library of capabilities for the model.”article, stated
“We’ve built an API endpoint on our internal OpenAI / LLM proxy that guarantees valid output. A key insight that enables this API is the LLM’s ability to repeat tags from the context in the answer reliably.”article, stated

Why this architecture

Instacart adopted a library of prompt-level controls because production LLM work failed in multiple small ways: context limits, hallucinations, task failure, invalid formats, and weak first drafts. Different workflows needed different control tactics, so the architecture keeps prompt techniques composable around an internal proxy and software actions.

“from context size issues, to hallucinations, to models that just don’t seem to be able to complete the tasks you set for them.”article, stated
“This article will be an exploration of prompt techniques we’ve used for our internal productivity tooling at Instacart.”article, stated

Models used: GPT-4 · GPT-3.5

Scale

Alternatives considered (roads not taken)

Ask the model for the final artifact in one pass

Rejected because: Room for Thought and Monte Carlo split intermediate reasoning or options before producing the final answer.

“First let’s create an outline for the pull request description. Do not generate a title and description, only write the outline.”article, implied

Let the model freely choose classifier labels

Rejected because: The internal proxy endpoint guarantees valid output and can use logit bias to nudge valid labels.

“We can nudge that probability by using the logit_bias parameter in our request to OpenAI, and if we set the bias to 100, we can force the model to choose from a specific set of tokens.”article, stated

Require the model to start in exactly the desired format unaided

Rejected because: Puppetry reduces formatting burden by telling the assistant it has already started responding.

“This decreases the burden on the model to start its response in the exact format you want for your output. It makes the model relax a little bit and just output the answer you want.”article, stated

Patterns

prompt-chaining (prompting)

Instacart uses multi-step prompt structures that let the model reason, act, and self-correct.

“Just as with the human intern, LLMs too, benefit from space to err and self-correct.”article, stated

tool-use-orchestration (prompting)

The ReAct-style prompt lets software execute external actions and resume the model task.

“Now when the model responds it may use INTERNAL_LOOKUP, GOOGLE_SEARCH, or calculation, and our software will perform the action and re-ask the model to complete the task with the new information.”article, stated

Tradeoffs

How to improve generated writing quality.

Chose intermediate outlines, multiple samples, and self-correction over single-pass final generation.

Rationale: Instacart found that forcing intermediate structure or sampling several options improved the final output for complex writing tasks.

“we ask the model to generate several different options, and then use those options to create a final answer”article, stated

How to keep classifier outputs valid.

Chose a proxy endpoint with constrained valid output and logit bias over unconstrained natural-language classification.

Rationale: Production code benefits from guaranteed label shape, while logit bias nudges ambiguous choices toward allowed outputs.

“We’ve built an API endpoint on our internal OpenAI / LLM proxy that guarantees valid output.”article, stated

Gotchas (what bit them)

LLMs need prompt scaffolding to reduce hallucination and format issues.

Root cause: The models are powerful but constrained by context and consistency challenges.

Resolution: The team used named prompt techniques rather than one-shot prompting.

“models knows that this emerging tech has limitless possibilities; Possibilities that are currently constrained by a number of challenges: from context size issues, to hallucinations, to models that just don’t seem to be able to complete the tasks you set for them.”article, stated

Evaluation

The article is a technique writeup and does not provide formal production metrics.

Outcomes

The article says the techniques were implemented and used with GPT-4.

“> A quick aside here: all of these prompt techniques have been implemented and used with GPT-4.”article, stated