Implementation Guide

Enforcing consistent prompt injection defense across different LLMs

Place prompt injection defenses in a layer outside the model that every model call passes through. Apply the same policy to user inputs, retrieved content, tool calls, and outputs. Give agents least-privilege permissions, log every policy decision, and run one regression suite against each model whenever it is added, swapped, or updated. Treat prompt injection as a risk to contain, not one that can be fully prevented.

Why model-native defenses are inconsistent

Each provider uses its own message format and its own tool-calling and system prompt conventions. Policy written in one provider's terms does not carry over cleanly to another.

For that reason, this guide places policy in a layer outside the model and keeps provider differences inside thin adapters, so the same policy applies whichever model handles the request.

A model-agnostic layered architecture

Assume the model can be manipulated and design the surrounding system so that a successful injection has limited consequences. Each layer below is enforced in a runtime layer, such as an LLM gateway or agent runtime, that sits between applications, models, and tools.

  1. Input normalization

    Canonicalize encoding, strip hidden or non-rendering characters, enforce size limits, and apply the same input screening regardless of destination model.

  2. Untrusted content handling

    Label retrieved documents, web content, and tool results as data, keep them separate from instructions in the prompt structure, and apply stricter policy to content from untrusted sources.

  3. Tool-call governance

    Parse every proposed tool call into a canonical schema and authorize it against the calling agent's permissions before execution.

  4. Output validation

    Check responses for schema conformance, sensitive data, and unexpected links or instructions before they reach users or downstream systems.

  5. Logging and audit

    Record each policy decision with enough context to reconstruct what was allowed or blocked and why.

Model-independent enforcement path

The table summarizes where enforcement happens relative to the model, from input to output.

Enforcement stages and what each one does
StageWhat happens
Inputs and retrieved contentNormalized and labeled by trust level before reaching any model.
Model layerAny commercial or open-weight LLM, treated as an untrusted component.
Tool callsAuthorized against agent permissions outside the model.
Outputs and logsValidated, then recorded with model and policy version.

Implementing the controls

Write policy in a model-independent form

Start by writing policy in a model-independent form. Policy should refer to agents, tools, data sources, and trust labels, never to a specific provider's message format. Add a thin adapter for each model that translates its tool-calling and system prompt conventions into one internal representation. Policy then evaluates the canonical form, and differences between providers stay inside the adapters.

Put tool-call governance first

Tool-call governance carries the most weight, because the damage from an injection usually comes from an action, not from text. Give each agent its own identity and a deny-by-default permission set scoped to the tools and data its task requires. Separate read-only from state-changing tools, and route high-impact actions, such as sending data externally or modifying records, through an approval step. A manipulated model can then request an action but cannot perform one outside its granted scope.

Expect tradeoffs

Additional checks add latency, screening produces false positives that need a tuning and exception process, and each adapter is code to maintain as providers change formats. Tighter permissions can also limit agent usefulness, so scope them per task and review them regularly.

Testing for equivalence and detecting drift

Run one regression suite against each model whenever it is added, swapped, or updated, so every model is held to the same policy outcomes.

Because each decision is logged with the model name and version, the adapter version, and the policy version, a change in behavior can be traced to a specific model, adapter, or policy change.

Audit data the enforcement layer should capture

  • Timestamp and request identifier linking input, model call, tool call, and output
  • Model name and version, and the adapter version in use
  • Agent identity and the permission set evaluated
  • Policy version and the rule that matched
  • Source and trust label of content that influenced the request
  • Decision (allowed, blocked, or sent for approval), the reason, and the approver where relevant

Review where policy is enforced in your AI stack

If model-native defenses currently carry most of your prompt injection protection, a review of runtime policy, agent permissions, and audit logging is a practical next step.

Request a Demo