← Blog

Turn Every Bedrock Stop Reason into a Response Policy

Parminder Singh
Parminder Singh··5 min read
Summarize with AI

Amazon Bedrock Converse returns one of nine documented stopReason values. A production response path should parse the field before delivery, assign each value a route-specific disposition, preserve unknown values for review, and keep transport success separate from semantic completion. This guide defines the policy states, audit evidence, streaming checks, and destructive fixtures needed at an authenticated HTTP boundary.

Platform & Architectureai-securityllm-securitycloud-securityarchitecturepolicy-enforcementaudit
Turn Every Bedrock Stop Reason into a Response Policy

Amazon Bedrock Converse returns stopReason beside the generated output. AWS currently documents nine values. They cover ordinary completion, tool use, configured stopping, and guardrail or filter intervention. Other values cover malformed output and context-window exhaustion. An HTTP 200 response can therefore contain output that your application should hold, route to a tool controller, retry under a bounded rule, or reject.

I would block delivery when the value is missing or unknown. Quietly treating a new provider state as end_turn is an unreviewed policy change.

TL;DR

  • Parse stopReason before any model bytes reach the authenticated caller.
  • Give all nine documented values an explicit route-specific disposition instead of treating HTTP 200 as completion.
  • Preserve the raw value, output digest, request identity, and model destination in the decision record. Record the policy version there too.
  • Handle the required stopReason in a ConverseStream messageStop event under the same policy.

Converse returns nine stop reasons

The Amazon Bedrock Converse API reference defines stopReason as the reason the model stopped generating output. Its current enum contains end_turn, tool_use, max_tokens, stop_sequence, guardrail_intervened, content_filtered, malformed_model_output, malformed_tool_use, and model_context_window_exceeded.

That field is part of the HTTP 200 response. Transport success says Bedrock returned a valid operation response. The stop reason says how generation ended. Keep those states separate in code and evidence.

Use a strict string parser. Require the field on routes that use Converse and preserve the exact token. Record the parser schema version and classify the token against a versioned enum. A missing value or wrong JSON type should enter a schema-drift disposition. The same disposition applies to an empty string or unknown string. Avoid coercing any of those states to a familiar reason.

The service-tier response validation guide uses the same evidence rule for another Bedrock response member: retain the provider value and attach a local conclusion without rewriting the original fact.

Each reason needs a delivery disposition

AWS defines the enum and identifies it as the reason generation stopped. Your application still owns the effect on delivery. Write that mapping into route policy rather than scattering conditionals across SDK callbacks.

A useful starting policy separates the values this way:

  • end_turn can proceed to output safety and authorization checks.
  • tool_use requires tool-name and argument validation before any executor sees it. Validate authority and side effects separately.
  • max_tokens enters a partial-output rule. High-assurance routes can hold it; another route can return a labeled truncation response.
  • stop_sequence requires comparison with the route's approved stop sequences and expected output contract.
  • guardrail_intervened and content_filtered use a controlled response path and retain the applicable assessment evidence.
  • malformed_model_output and malformed_tool_use block the candidate result and enter a bounded error or retry path.
  • model_context_window_exceeded returns a controlled request failure or starts an approved context-reduction workflow.

Those are local dispositions, not AWS guarantees about content quality. The tool-call policy enforcement guide covers the authorization work that begins after tool_use.

Partial completion needs its own state

max_tokens and stop_sequence deserve more than a generic success flag. A response can contain readable text while ending before the application's required structure or closing statement arrives. A JSON parser may reject the fragment. Plain prose can look finished while omitting the final constraint.

For max_tokens, record the requested token limit and returned usage. Preserve the response digest and delivery outcome too. Then apply the route's partial-output rule. A bounded continuation can be acceptable for a drafting route. A customer-facing eligibility explanation may require a fresh request and full validation before release.

For stop_sequence, bind the approved sequence list to the route and preserve the provider reason. If the application expects one sentinel, validate the model-native response detail only when that field was separately requested and allowed. Do not infer which sequence fired from the generic reason alone.

Put the final state on the operations screen in a square badge beside the response digest. Amber can mean held partial output, while red marks blocked malformed output. The raw stopReason should remain visible in monospace text rather than hiding behind the color.

Streaming policy runs at messageStop

Streaming changes the timing of enforcement. The Bedrock MessageStopEvent reference requires stopReason on the final message stop event and uses the same nine-value enum. If the application forwards content deltas before that event arrives, it loses the ability to prevent delivery based on the final stop state.

High-assurance routes should buffer the candidate stream until the terminal event passes policy. Routes that intentionally stream live need a documented residual-risk decision because a late guardrail_intervened or content_filtered state can arrive after earlier bytes reached the caller. A malformed state or context-window state can do the same.

Treat a stream that closes without messageStop as incomplete. Record the last accepted event and released byte count. Preserve the provider request identifier and local disposition too. Retry only under the route's idempotency and side-effect rules. The safe LLM retry guide covers correlation and ambiguous outcomes across attempts.

Decision records keep provider fact and local action separate

Retain the raw response in restricted evidence when policy permits. Write a smaller decision record containing caller or agent identity, application route, model resource, AWS Region, HTTP status, provider request identifier, raw stop reason, parser schema version, response digest, content-release count, local policy version, and final disposition.

Keep two fields for provider fact and local action. stop_reason: max_tokens describes Bedrock's response. delivery_disposition: hold_partial describes your decision. Combining them into success: false destroys the evidence needed to understand what happened.

The AI audit log schema guide provides common identity, correlation, destination, and policy fields. Add Bedrock-specific response members under a versioned extension. Raw prompts and outputs need classification and access control. They also need retention rules. A digest supports correlation when plaintext retention is prohibited, though it cannot reconstruct a malformed payload during investigation.

Release tests cover every terminal state

Build one fixture for each of the nine documented values. For every fixture, assert the user-visible response and delivery disposition. Check bytes released, tool executions, retries, the decision record, and any alert or review state.

Add destructive cases for an absent field, null, an array, a mixed-case value, an empty string, and a future-looking token such as policy_timeout. Include an HTTP error that contains no Converse response and malformed JSON. Also include a valid end_turn whose output later fails content policy. That last fixture proves the stop reason never bypasses other response checks.

Run the same matrix through streaming. Test a valid messageStop, a stream that ends before the terminal event, duplicate terminal events, and content deltas followed by each blocked reason. If a route streams bytes before terminal validation, the release report should state the exact byte count already exposed.

DeepInspect

DeepInspect can enforce this response policy on authenticated user or agent HTTP traffic deliberately routed through its proxy to Amazon Bedrock. It can hold the candidate response, validate the stop reason, bind the outcome to caller identity and route policy, and write a per-decision audit record before delivery.

AWS remains responsible for the stop reason and model response it returns. Application owners define route dispositions, tool execution, retry behavior, and downstream effects. Direct Bedrock calls, local inference, STDIO traffic, and HTTP paths that bypass the proxy remain outside DeepInspect's enforcement boundary.

Book a technical deep dive at deepinspect.ai.

Frequently asked questions

Does end_turn mean the response is safe to deliver?

end_turn identifies how generation stopped. Content safety, data-loss policy, output schema, identity authorization, and application-specific checks remain separate. A route can accept the stop state and still block the response under another policy.

Should tool_use be shown directly to the user?

Send it through the tool-control path first. Validate the tool name, arguments, caller authority, side-effect class, and correlation identifier. The tool request becomes executable only after those checks pass.

Can an application retry malformed_model_output automatically?

A bounded retry can fit a reviewed route, but it needs a new attempt identifier, a hard limit, evidence linking every candidate response, and suppressed downstream side effects. Any downstream side effect must remain suppressed until one accepted response passes policy.

What happens when AWS adds a new stop reason?

Preserve the raw string and classify it as unknown under the current parser. Stop logic that assumes one of the known states. Review the current AWS reference, update the policy mapping, add a fixture, and then promote the parser revision.