Sequence Enforcement for AI Agents: Why Step Order Is a Security Property
A credit AI agent with a declared workflow of identity_check → fraud_check → risk_score → approve_credit should not be able to jump from identity_check straight to approve_credit. Not because the model will make a wrong decision — it might not — but because the sequence contract is a security property. Step order declares which prerequisites must complete before each action is permitted. Sequence enforcement is the external gate mechanism that makes the contract real at runtime. Without it, the order is a convention. Conventions bend under prompt injection, misconfiguration, and edge cases. Enforcement does not.
See sequence enforcement run live — submit steps out of order and watch SEQUENCE_VIOLATION fire before any action executes.
What sequence enforcement is
Sequence enforcement is the mechanism that verifies step order at runtime against a declared contract, before each action is permitted to execute. The contract is simple: a named, ordered list of steps. The gate maintains a ledger of completed steps for each sequence. When a new step arrives, the gate answers a single question: is this the next expected step?
If yes — and the nonce is fresh, the timestamp is valid, and the function and action type are permitted — the gate returns ALLOW. The step proceeds and is recorded in a signed receipt.
If no — the submitted step is not the next expected step, or a prior required step has not completed — the gate returns DENY with reason code SEQUENCE_VIOLATION. The action does not execute. The denial is recorded before execution.
This is the entire mechanism. There is no scoring, no inference, no model involved in the decision. The sequence contract is a policy. The gate enforces it deterministically.
Step order as a security boundary, not a logging convention
Most teams implement step order as a convention — the agent is prompted to follow a workflow, and the application layer logs what happened. This is not enforcement. It is observation.
The distinction matters because the threat model for agentic AI includes the agent itself. LLM-based agents can be manipulated through their input — adversarial prompts, injected context, misconfigured tools. If step order is enforced only by the agent's own reasoning, it is only as robust as the agent's reasoning is resistant to manipulation. In a well-resourced attack, that resistance is finite.
A financial AI agent is prompted to follow the workflow: identity_check → fraud_check → risk_score → approve_credit. The agent's tool-calling logic is manipulated through a crafted input that causes it to invoke the approve_credit tool directly, before fraud_check runs. The application layer logs the approval. The fraud check step is missing from the log. The approval executed without the prerequisite check.
With enforcement: the gate receives approve_credit when the expected next step is fraud_check. DENY. SEQUENCE_VIOLATION. The action does not execute. The denial is recorded before the action is attempted.
Sequence enforcement converts step order from a convention that depends on the agent into a hard gate that is external to the agent. The agent's reasoning is not involved in the enforcement decision. The gate evaluates sequence state independently — it does not parse the agent's context or trust the agent's self-report of its position in the workflow.
The sequence contract: declared once, enforced at every step
The sequence contract is declared at configuration time: an ordered list of step names with the permitted function, action types, and sequence position for each. At runtime, the gate enforces this contract on every step submission without exception.
Every step submission is evaluated against this contract. The gate does not check steps at the end of the sequence or on request — it checks every step before it executes. If step 3 arrives before step 2 is recorded, DENY fires. If step 1 is submitted again after completing, DENY fires with REPLAY_NONCE. If step 4 is submitted after the sequence is sealed, DENY fires with SEALED_SEQUENCE.
What SEQUENCE_VIOLATION actually catches
The SEQUENCE_VIOLATION denial fires in three scenarios. Each represents a distinct enforcement outcome:
| Scenario | What happened | Enforcement outcome |
|---|---|---|
| Step skipped | Agent submitted step 4 without completing step 2 or 3 | DENY · SEQUENCE_VIOLATION |
| Prompt injection | Adversarial input caused agent to invoke an out-of-order tool call | DENY · SEQUENCE_VIOLATION |
| Replay attempt | Completed sequence replayed from step 1 with original nonces | DENY · REPLAY_NONCE |
| Post-seal submission | Step submitted to a sequence that has already completed | DENY · SEALED_SEQUENCE |
| All conditions met | Step is next in sequence, nonce fresh, timestamp valid, policy permits | ALLOW |
Every DENY is recorded in a tamper-evident receipt before the action is attempted. The receipt contains the sequence ID, the step that was submitted, the expected next step, the nonce, and the timestamp — HMAC-signed before storage. An auditor can verify any DENY receipt with the signing key. The sequence violation is proven, not asserted.
A SEQUENCE_VIOLATION receipt
Sealing: the final enforcement state
When the final step in a declared sequence completes, the sequence is sealed. The seal is permanent — there is no unsealing mechanism. Any further step submission to a sealed sequence returns DENY with reason code SEALED_SEQUENCE.
Sealing serves two enforcement purposes. First, it prevents replay after completion: an attacker cannot re-run an approved sequence to extract capabilities that were valid during the original run. Second, it prevents extension attacks: additional steps cannot be appended to a completed sequence to claim authority that was not part of the original workflow.
The sealed sequence receipt is the affirmative compliance record: all declared steps completed in order, no steps were skipped, no replay occurred, no post-completion actions were permitted. It is the sequence enforcement equivalent of a closed audit period.
Compliance frameworks and sequence enforcement
Run a sequence in the demo, skip a step, and see SEQUENCE_VIOLATION fire — with a signed receipt written before the action attempted to execute.