AWS Builder Center

Steering Hooks: Deterministic, Just-in-Time Behavioral Control for LLM Agents

Prompt-based rules degrade under load and workflow graphs break the moment a request doesn't fit their path. This post shows a third option: deterministic checks at the tool-call boundary that outperform both in a published benchmark and hold up in a real production refactor.



A bug that looks small until you trace it

Picture an internal assistant that helps ops reps manage customer orders. A rep types:
"Bump the quantity on order 48213 to 40 units."
The agent calls  search_orders , finds the order, calls  present_update_form  to show the rep exactly what's about to change, and waits for confirmation. That's the intended flow.

Except one day it doesn't wait. The agent calls  execute_order_update  directly, skipping the confirmation step entirely. The quantity changes before the rep ever saw the form. Nothing crashed. No error appeared. The agent was, by every measure, doing its job—just not in the order anyone designed for.

This is a one-line bug with a deep cause. The agent needs to call  present_update_form  before it's allowed to call  execute_order_update , and nothing in the system actually enforces that. It's a suggestion, not a rule.

Two fixes, and why each one leaks

The obvious first fix is to tell the model:
"Always call  present_update_form  before calling  execute_order_update ."
Add that line to the system prompt and the bug mostly goes away. Mostly. It competes with every other instruction already in that prompt—persona guidance, tone rules, formatting requirements, a dozen other behavioral constraints accumulated over months. Add a fifteenth rule and the model starts quietly dropping the third one. Everything in the prompt competes for the same finite attention, on every turn, whether that rule is relevant to the current request or not.
A much more detailed standard operating procedure closes most of that gap. It also means resending the entire procedure as prompt text on every turn, paying the token cost whether the request touches ordering rules or not.
The second fix goes the other way: stop asking, start constraining. Build an explicit workflow graph—nodes for search, select, map fields, present, execute—and wire the edges so  execute  is structurally unreachable before  present . The ordering is now enforced by the graph, not requested of the model.
This works well on the path the graph was built for. It fails the moment a rep does something the graph didn't anticipate: asks a clarifying question mid-workflow, changes their mind about which order they meant, or asks something unrelated like "what's our return policy on bulk orders?" The graph has no node for that. It routes to a catch-all that loses context, or it fails outright.
Both fixes make the same mistake: each tries to hold a deterministic rule using a mechanism of the wrong shape. The prompt is probabilistic—fine for tone and persona, unreliable for a rule that must always hold. The graph is deterministic but rigid—correct on the one path it encodes, brittle everywhere else.


Enforce the rule at the boundary, not in the model's head

Stop trying to get the ordering rule enforced inside the model's reasoning, whether by prompt or by graph. Enforce it at the one point where enforcement can be perfectly deterministic without touching the model's reasoning at all: the boundary between the agent deciding to call a tool and the tool actually running.
Every agent framework that supports tool use has, or can be given, a point right before a tool call executes. Register a plain function there. It inspects the proposed tool name and its parameters, checks whatever state the rule cares about, and either lets the call through or cancels it with a plain-language explanation. Here's the actual predicate for the order-update rule:
def enforce_ordering(event, state):
if event.tool_use["name"] != "execute_order_update":
return

if not state.operation_completed("present_update_form"):
event.cancel_tool = (
"Cannot execute the order update before presenting "
"the update form. Call present_update_form first."
)
This function isn't calling another LLM to check the request. It isn't routing through a graph node. It's five lines of ordinary, deterministic code that runs the same way every time it's invoked. It only runs at the moment  execute_order_update  is proposed—not on every turn regardless of relevance, the way a prompt rule does.
When the hook cancels the call, the agent doesn't crash or dead-end. It gets the cancellation message back the same way it would get back a tool error, reads it, and typically self-corrects within the same turn by calling  present_update_form  first and retrying. The model's reasoning stays intact. Only the one governed operation was gated.

What a before-call steering hook actually is

A before-call steering hook is a deterministic function, registered at the tool-call boundary, that inspects a proposed operation and either allows it or cancels it with guidance the agent can act on.
Three properties define it, and each one is doing real work.
It inspects before execution, not after. By the time a mutating call has run, you're validating a fait accompli. The check has to happen before the side effect.
It cancels with guidance, not a hard failure. The agent reads a message and decides what to do next—same channel as a tool error, so no new failure mode to teach the model about.
It doesn't care where state comes from. The predicate above calls  state.operation_completed(...) . It doesn't know or care if that's backed by a database, an in-memory flag, or a session object. That's an application concern, kept out of the hook mechanism on purpose.
The third property is why the same shape works for rules that have nothing to do with ordering. A validation hook inspects the proposed parameters and cancels if a price is negative or a date is malformed. An authorization hook inspects the current user's role and cancels a mutating call they're not permitted to make. Same mechanism—inspect, decide, allow or cancel-with-guidance—applied to a different rule.
Property
Prompt / Graph
Steering Hooks
Where the rule lives
In the model's context (prompt) or in explicit control flow (graph)
In a plain function at the tool-call boundary
Determinism
Probabilistic (prompt) or absolute-but-rigid (graph)
Absolute, and only where it applies
Cost per turn
Full rule text resent every turn (SOP), or full graph traversal
Rule only evaluated when a relevant tool is called
Behavior off the happy path
Prompt degrades; graph fails or routes to a catch-all
Agent retains full reasoning; only the specific call is gated
Testability
Hard to unit test a prompt; graph requires running the framework
Pure function—unit-testable in isolation

The numbers back this up

A  published evaluation  ran 3,000 test cases across five approaches to controlling agent behavior: no instructions, simple prompt-based instructions, a detailed SOP, a graph-based workflow, and steering hooks.
Approach
Pass Rate
Input Tokens
Output Tokens
No instructions
15.7%
1,870
401
Simple prompt instructions
82.5%
2,329
430
SOP (detailed prompt)
99.8%
9,879
459
Steering hooks
100.0%
3,346
598
Graph-based workflow
80.8%
3,116
1,125
Three things stand out. Steering hooks scored the highest pass rate of any approach tested, ahead of even the exhaustively detailed SOP. They did it using 66% fewer input tokens than that SOP, because the rule logic isn't resent as prompt text every turn—it only fires when a governed tool call happens. And they used 47% fewer output tokens than the graph, because there's no per-node intermediate response overhead.
The graph's pass rate is the more telling number. Whenever a request didn't fit its predefined path, the graph-based agent failed the overwhelming majority of the time—the exact brittleness the order-form example predicted. Steering hooks enforce the identical ordering constraint without that failure mode, because the agent is never inside a graph node to begin with. It always has its full tool set and reasoning available. The hook only ever touches the one call that needs gating.


A general design principle, independent of any specific framework or SDK

Put deterministic rules where determinism is cheap—the boundary between decision and action—and leave everything else to the model's own reasoning.
Prompt-based control tries to make a probabilistic system behave deterministically by asking nicely, repeatedly, at rising token cost. Graph-based control achieves determinism by removing the model's freedom everywhere, not just at the one point that needed it. Steering hooks are deterministic exactly where they need to be and nowhere else: a plain function at a well-defined boundary, with the rest of the conversation left entirely to the agent.

Does it hold up on a real system, not just a toy example?

The pattern was tested against the architecture of a production AI assistant used for internal order management. The existing system had one orchestrator agent plus three specialist agents behind it: one for order search and update, one for pricing and catalog questions, one for product documentation lookups. Each specialist ran in its own container with its own agent runtime. The orchestrator classified the user's intent, picked a specialist, invoked it over the network, and streamed its response back to the frontend. The order-update specialist additionally ran its own internal workflow graph—search, select, map fields, present, execute, plus half a dozen pause points added over time for edge cases like disambiguating which order the user meant.
This produced two nested control mechanisms doing the same conceptual job: an agent router deciding which specialist should handle a request, and a workflow graph deciding what that specialist could do next. Both existed to enforce ordering and routing rules that don't need a router or a graph. They need a boundary check.
The architecture accumulated real, measurable costs along the way.
Latency. Every specialist call was a network hop through a separate agent runtime, adding several seconds. Multi-intent requests touching more than one specialist paid this cost more than once.
Redundant inference. The orchestrator burned one model call just to classify intent and pick a specialist; the specialist then burned a second model call to actually do the work. Even "look up order 48213" paid for two model invocations. The team's own fix—a keyword pre-classifier bolted in front of the LLM router to catch obvious cases cheaply—is itself evidence of the cost: a second routing system, with its own configuration and its own failure modes, built specifically to work around the first one.
Context loss. Specialist agents ran as stateless, independently-scaled processes with no shared way to say "this is the order we're currently discussing." The workaround was a marker written into the event log and a fast-path in-memory cache, both with limited lookback. A rep who selected an order, had a few turns of unrelated conversation, and then asked a follow-up question would get told no order was selected. Not a one-off bug. A structural consequence of context having to survive as data smuggled through a log instead of living in one process.
Operational overhead. Four container images, four deployments, four sets of configuration to keep in sync on every change.
Rigid workflow enforcement. The same brittleness as the toy example, at production scale. Every new edge case meant another pause point wired into the graph, and every pause point increased the graph's surface area rather than shrinking it.
A fragile streaming contract. Each specialist streamed its real output over one channel while the orchestrator's tool-calling layer expected a return value on another, kept in sync by convention rather than by the type system. Get it wrong and every response rendered twice. This is exactly the kind of rule a boundary check enforces deterministically. In the original system it was enforced only by a code comment and reviewer vigilance.
The prototype replaced both control layers—the orchestrator's routing and the specialist's internal graph—with one agent that had direct access to the same underlying capabilities, governed by three before-call hooks: one enforcing the update-ordering predicate, one validating parameters before they reached the API layer, one checking authorization before a mutating call. The existing API clients, product-documentation integration, and the frontend's event contract were left untouched. Only the control layer changed.
Aspect
Before (multi-agent + graph)
Prototype (single agent + hooks)
Agent topology
1 orchestrator + 3 specialists
1 unified agent
Containers / runtimes
4 of each
1 of each
Routing
Keyword pre-classifier or LLM router, then network call
Model selects domain tools directly
Update ordering
Workflow graph with nodes, edges, and persisted pauses
Before-call hook evaluating an explicit state predicate
Order context
Persisted marker plus per-process cache
Shared agent state
Streaming
Specialist stream forwarded through orchestrator tool
Single stream adapted to the existing event protocol
Four things came out of this directly. The same ordering rule from the toy example reduced to the same small hook predicate at real-system scale. One agent entrypoint could expose everything the three specialists used to own, as ordinary tools, while still calling the same underlying API clients. Related operations could share the state a hook needs without crossing a specialist-agent boundary to get it. The existing frontend contract survived untouched by adapting the unified agent's event stream to it, rather than redesigning the protocol.
To be precise about what this prototype does not claim: it wasn't deployed as the production system, it didn't run a full regression pass across every update variant, and nobody measured latency or cost against the original architecture in a controlled way. Removing a network hop and a redundant model call should improve both by construction, but "should" isn't "measured." That comparison is future work.

Takeaways

Encode rules as functions, not as sentences. A rule that must hold deterministically should be enforced by a deterministic function, not requested of a probabilistic one. Save the prompt for persona and general guidance.
Cancel with guidance, never with a crash. The value over a hard failure is that the agent reads the cancellation and self-corrects in the same turn, instead of the conversation dead-ending.
Define explicit state predicates, not hidden workflow assumptions. When a rule depends on prior activity, name the exact state the hook checks. The hook mechanism itself shouldn't care where that state lives.
Reach for one agent when specialists exist only to route. Separate agents earn their keep when they need different trust boundaries, models, or scaling profiles. When they exist purely to partition one tool set behind a router, a single agent with hooks removes the network hops and duplicate inference without losing any of the determinism.
None of this is specific to one SDK or framework. Behavioral rules for a tool-calling agent belong at the tool-call boundary. Not in the prompt. Not in a workflow graph.


This post is adapted from a longer technical writeup that includes the full benchmark methodology, additional implementation detail, and a discussion of open questions around composing multiple hooks and measuring their runtime overhead at scale.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article