Stop Instruction Smuggling With Fixed Schema Enums

November 14, 2026·4 min read·Prompt Airchitect
  • llm security
  • prompt engineering
  • ai pipelines
  • pydantic
  • data architecture
A rigid gate partition blocks chaotic paper debris from passing through a pipeline, allowing only clean spheres to exit on the other side.

In short

  • Freeform intermediate LLM outputs are susceptible to instruction smuggling, where malicious inputs overwrite downstream system prompts.
  • Using Enum-constrained schemas forces models into a classification role, preventing them from generating executable malicious strings.
  • Models may attempt to force-categorize ambiguous data as 'safe' to satisfy schema requirements unless a restrictive 'catch-all' state is provided.
  • True security in multi-node workflows is achieved by passing indirect references (IDs) rather than the raw data itself.

Eliminating Inter-Node Context Bleed with Fixed-Schema Enums

We prevent instruction smuggling in multi-step LLM workflows by replacing freeform text handoffs with strict, enum-based state transitions. By restricting intermediate outputs to a predefined set of scalar keys, you effectively neutralize an LLM's ability to inject malicious instructions into downstream nodes while preserving the integrity of downstream tool call execution.

Technical takeaways

  • Vulnerability Mitigation: Freeform intermediate text responses allow upstream nodes to propagate "Instruction Smuggling," where malicious input in Node A re-writes the system prompt of Node B.
  • Security Layering: Enforcing a Pydantic Enum schema at the serialization layer acts as a boundary for the LLM, ensuring only sanctioned, non-executable states are passed between pipeline nodes.
  • Reliability: Deterministic state transitions via rigid schemas prevent hallucinations, ensuring that downstream tools receive inputs that align with strict type signatures.

The mechanics of context bleed

Context bleed occurs when an LLM, tasked with summarizing data to pass to a downstream agent, inadvertently interprets an input attack—such as a prompt injection—as a set of direct instructions. We have observed that if an input contains an instruction to override system behavior, the model often echoes this command within its summary. When Node B receives this output, it treats the summary not as objective data, but as context to be followed.

A robot processes a jagged, threatening message that causes the receiving robot to malfunction.
A robot processes a jagged, threatening message that causes the receiving robot to malfunction.

We identified that standard "Cleaning" nodes—LLMs tasked with stripping malicious text—are inherently flawed because they are susceptible to the same injection vectors they are intended to sanitize. Instead, we architected a system where the permissible data transfer is a narrow JSON object containing an Enum-constrained state and a reference pointer.

Implementing Enum-based state transition

By defining a formal schema, you shift the LLM’s role from "writer" to "classifier." The model no longer generates freeform prose; it performs a selection task that is structurally validated before hitting the next node in the pipeline.

from enum import Enum
from pydantic import BaseModel, Field

# Using an Enum forces the model to select from a static list
# preventing it from hallucinating its own instructions.
class WorkflowState(str, Enum):
    PROCESSED_SAFE = "PROCESSED_SAFE"
    NEEDS_PII_MASKING = "NEEDS_PII_MASKING"
    ESCALATE_TO_HUMAN = "ESCALATE_TO_HUMAN"
    REJECTED_SECURITY_POLICY = "REJECTED_SECURITY_POLICY"

class PipelineHandoff(BaseModel):
    state: WorkflowState = Field(..., description="The definitive status of the node processing.")
    entity_id: str = Field(..., description="A safe primary key, never the original text.")

When you define your system prompt, instruct the model that any reasoning or "inner monologue" must be performed in a separate, isolated scratchpad, and only the final PipelineHandoff object should be emitted. Because the output is strictly typed, any injection attempt—which typically manifests as an verbose, unformatted string—results in an immediate ValidationError at the deserialization layer, halting the pipeline before Node B is ever invoked.

The Hidden Trap: Schema Coercion

A common mistake among engineers is assuming the LLM respects the Enum boundary under all circumstances. In practice, models exhibit "forced categorization" behavior. When an input is ambiguous, the model may experience internal pressure to satisfy the schema, leading it to select a PROCESSED_SAFE label for a malicious input simply because it exhausted its reasoning capacity.

This is the non-obvious failure point: the model treats the Enum as a suggestion rather than a hard boundary. If you do not provide an UNKNOWN or REJECTED state, the model will coerce dangerous data into a safe bucket just to satisfy the schema constraint, effectively "greenlighting" malicious payloads through the validator. Always include a CATCH_ALL state and explicitly prompt the model that if it cannot confidently classify, it must default to the most restrictive state.

Architecting for 'Indirect Reference'

To truly eliminate context bleed, stop passing content between nodes entirely. Instead, use an "Indirect Reference" pattern. In this architecture, Node A writes its findings to a protected data store and passes only the entity_id and the WorkflowState enum downstream.

A secure architecture where metadata and raw data flow through separate channels to prevent command injection.
A secure architecture where metadata and raw data flow through separate channels to prevent command injection.

When Node B executes, it performs a lookup using the entity_id to retrieve the original, untrusted source data. This is the core of the security model: decoupling the control flow from the data flow.

Even if Node A is successfully compromised, the attacker only influences the state label, not the actual execution instructions. Because Node B fetches the raw payload from a trusted datastore rather than the output of Node A, it remains insulated from whatever prompt injection was present in the upstream input. This creates an auditable state machine where every transition is recorded with a traceable identity, leaving no room for the LLM to inject hidden, non-sanctioned commands into the execution context of the next node.

By treating the Enum handoff as a pure "control signal" and the secondary data fetch as a distinct, permissioned operation, you prevent the LLM from ever having the opportunity to "interpret" the content it is processing as an instruction. This structural separation is the only way to achieve true multi-node security, as it renders the content of the transmission irrelevant to the logic of the pipeline.

Want the prompt this article describes, built for your own objective?

Engineer one now — free, no account needed