Repository navigation
feat(openrouter): capture safeguard_results and alignment in span metadata - #980
Merged
Abhijeet Prasad (AbhiPrasad) merged 1 commit intoOct 19, 2026
Conversation
…adata OpenRouter chat results, chat stream chunks, and Responses results now carry `safeguard_results` (Armor verdicts) and `alignment` (alignment plugin results). Surface both in span metadata, including for streamed chat where they only appear on the final chunk. Closes #974 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Abhijeet Prasad (AbhiPrasad)
deleted the
abhi/openrouter-safeguard-armo-d74b8ec4
branch
October 19, 2026 22:40
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #974
resolves https://linear.app/braintrustdata/issue/SDK-590
AI Summary
Problem
OpenRouter added two plugin-driven fields to its responses:
safeguard_results: Armor's verdict for each client tool call, keyed by tool-call idalignment: alignment plugin call records (beta)They show up on chat results, chat stream chunks, and Responses results. The OpenRouter integration picks span metadata from fixed allowlists, and neither field was on them. So when Armor blocked or flagged a tool call, the span showed no trace of it. That's exactly the signal you want when you're debugging why a tool never ran.
Here's what OpenRouter returns when Armor blocks a call:
Streamed chat was worse off than non-streamed chat. OpenRouter sends
safeguard_resultsonly on the final chunk, and the chat stream aggregator never read any response-level fields from chunks at all:Fix
1. One shared key list, added to both response allowlists. Non-streamed chat and Responses (streamed and not) already go through
_pick_response_metadata, so these paths only needed the new keys:2. The chat stream aggregator now returns response metadata. It keeps the last non-None value of each safeguard key it sees, so the final chunk's verdict ends up on the span:
_aggregate_chat_streamnow returns(output, usage, response_metadata), the same shape as_aggregate_responses_stream. That lets_finalize_streammerge metadata in one place for both stream kinds:Streamed chat picks up only the safeguard keys from chunks. It does not go through
_pick_response_metadata, because that would also copymodel/providerfrom each chunk and overwrite the request-side values these spans log today.openrouter:armor_blockedoutput itemsWith Armor's
output_mode: "custom_item"(Responses API), a blocked call is replaced by anopenrouter:armor_blockedoutput item. The SDK parses it into a typedOutputArmorBlockedItem, and the existing Responses output path already logs it as a clean dict, so this needed no code change:call_idon the blocked item matches the key inmetadata.safeguard_results[0].status.tool_uses, so you can join a blocked call to its verdict from the span alone.🤖 Generated with Claude Code