Untrusted source becomes instruction
Detect: Injected document text changes tool behavior.
Recover: Preserve data boundaries and enforce tool authorization outside the model.
Build each model request from versioned policy, authorized evidence, task state, and a deliberate token allocation.
Dynamic prompt assembly constructs a request from several sources at runtime rather than concatenating a fixed template with a user message. The assembler selects relevant instructions, tool definitions, conversation state, retrieved evidence, and output constraints. Its architectural role is to preserve priority and provenance while adapting context to the task.
Assembly is a trust boundary. Retrieved documents and tool results are data even when they contain imperative language. Policy instructions must remain application-controlled, and user-supplied text must not be promoted into a privileged instruction slot. A manifest of selected segments makes requests reproducible without storing unrestricted sensitive payloads in general logs.
A prototype separates instruction templates from user and retrieval data and records prompt versions.
Production applies authorization before inclusion, token budgeting, structured delimiters, and deterministic segment ordering.
Enterprise scale adds policy-version rollout, prompt manifests, locale-specific templates, and evaluation of assembly changes across task and data classes.
Stores reviewed instruction and output-contract versions.
Chooses task-relevant history and authorized source evidence.
Determines applicable tenant, data, and tool restrictions.
Reserves room for output and allocates context by priority.
Records segment identities, versions, trust levels, and exclusion reasons.
flowchart TD
P["Reviewed policy templates"] --> A["Prompt assembler"]
T["Task and output contract"] --> A
E["Authorized evidence"] --> B["Data segment boundary"]
H["Selected conversation state"] --> B
B --> A
A --> K["Token and schema validation"]
K --> M["Model request and manifest"]Determine requested output, model capability, and applicable policy.
Load instructions, conversation state, evidence, and tool schemas with provenance.
Reject unauthorized evidence and keep untrusted content in clearly bounded data fields.
Reserve output capacity and choose segments according to task value and required constraints.
Render stable instructions first and changing task data in consistent locations.
Check size and schema, then record the manifest and evaluate the response against its contract.
Human resources · Illustrative enterprise scenario, not a reported customer outcome.
An employee assistant uses company policies, regional addenda, and the employee’s selected locale.
A single oversized prompt mixes irrelevant regions and sometimes includes obsolete policy fragments.
Assemble only applicable evidence while preserving access limits and a consistent answer format.
The policy resolver selects the region, the retriever supplies authorized active documents, and the assembler creates a versioned manifest.
If mandatory policy text cannot fit, assembly fails explicitly or chooses a supported larger-context route instead of silently dropping it.
Track assembly failures, excluded evidence, token use, and policy-citation accuracy; reproducible manifests help explain behavior changes.
| Decision | Benefit | Cost |
|---|---|---|
| Task-specific context | Reduces irrelevant tokens. | Requires selection logic and evaluation. |
| Deterministic ordering | Supports reproducibility and possible prefix reuse. | Can constrain adaptive placement strategies. |
| Detailed manifests | Improve auditability. | Need privacy-aware storage and retention. |
Detect: Injected document text changes tool behavior.
Recover: Preserve data boundaries and enforce tool authorization outside the model.
Detect: Responses ignore a required policy constraint.
Recover: Validate segment retention and reject oversized assemblies.
Use typed segments with explicit trust and provenance.
Reserve mandatory policy capacity before optional evidence.
Store restricted manifests and governed payload references.