XI · Structure & DataMature★★

Prompt/Response Optimiser

also known as Prompt Template Runtime, Runtime Prompt Refinement, Prompt Standardiser

At runtime, transform user inputs and model outputs into standardised, template-aligned prompts and responses against predefined constraints, so the agent and its downstream consumers see consistent shapes.

Context

A team is running an agent that sits between free-form human input on one side and a chain of downstream consumers on the other — other agents, tool calls, and user-interface components that each expect a particular shape. Users write whatever they want, in whatever phrasing they want, and downstream code expects predictable structure. The team needs a place to standardise both ends without asking either side to change its habits.

Problem

If user prompts go straight to the model and the model's free-form output goes straight to consumers, two things drift in parallel. The model's behaviour changes with every small wording variation in how users phrase the same intent, and each downstream consumer ends up writing its own ad-hoc parser to extract what it needs from prose, with parsers that disagree on edge cases. Over time the agent's behaviour becomes hard to reproduce and downstream integrations become brittle, because there is no single contract that both the model and the consumers are held to.

Forces

  • Standardisation: consistent shape across prompts and responses helps reliability.
  • Goal alignment: optimisation must serve the user's actual goal, not just template compliance.
  • Interoperability: other tools/agents need predictable shapes.
  • Adaptability: templates must accommodate different domains and constraints.

Example

An onboarding agent accepts any free-form question from a new employee. A prompt/response optimiser wraps every user message in a template that restates the company policy context, the employee's department, and the required output format (a JSON object with answer + citation). The model never sees raw user wording without that frame, and the downstream UI always renders a predictable shape.

Diagram

Solution

Therefore:

A prompt/response optimiser sits between the user-facing surface and the foundation model. On input, it loads a template for the current task (few-shot examples, format constraints, goal restatement) and rewrites the user's prompt to match. On output, it post-processes the model's response into the consumer's expected shape. The template registry can be evolved independently of the agent logic.

What this pattern forbids. Both the model and the downstream consumers see only template-conformant shapes; raw user wording does not propagate.

The smaller patterns that complete this one —

  • usesPassive Goal CreatorAnalyse the user's articulated prompts and accompanying context to derive a precise, actionable goal before any planning or tool use begins.
  • usesProactive Goal CreatorAnticipate the user's goal by capturing surrounding multimodal context (gestures, screen state, environment) in addition to what the user types or says.

And the patterns that stand alongside it, or against it —

  • complementsPrompt Versioning★★Treat prompts as immutable, hashed, semver'd artefacts in a registry; deploy and roll back like code.
  • complementsDynamic ScaffoldingInject task-specific scaffolding (examples, hints, schemas) into the prompt only when the task type warrants it.
  • composes-withStructured Output★★Constrain the model's output to conform to a JSON Schema (or similar typed shape).
  • alternative-toDSPy SignaturesSpecify agent behaviour as declarative typed signatures and modules; compile prompts and few-shot examples automatically against a metric.

Neighbourhood

Click any neighbour to follow the language. Scroll to zoom, drag to pan.