fix(guardrails): prevent bypass of blocked Tool Result Policy when context is sensitive#4250
Open
wengkit218-pixel wants to merge 2 commits intoarchestra-ai:mainfrom
Conversation
…ntext is sensitive When an agent has 'Treat context as sensitive from the start of chat' enabled, blocked Tool Result Policies were being bypassed. The function returned early when considerContextUntrusted was true, skipping the Tool Result Policy evaluation entirely. Root cause: In trusted-data.ts, evaluateIfContextIsTrusted() returned early around line 68 when considerContextUntrusted was true, so it skipped the real Tool Result Policy evaluation around line 125 and returned empty toolResultUpdates. Fix: Instead of returning early, we now set contextIsTrusted=false and unsafeContextBoundary, then continue to evaluate Tool Result Policies. This ensures blocked tool results are properly replaced with the blocked message before being sent to the model. Fixes archestra-ai#4225 /claim archestra-ai#4225
Contributor
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.
Summary
Fixes #4225
When an agent has \Treat context as sensitive from the start of chat\ enabled, blocked Tool Result Policies were being bypassed. The raw tool result was sent to the model instead of being replaced with the blocked message.
Root Cause
In \platform/backend/src/guardrails/trusted-data.ts, \evaluateIfContextIsTrusted()\ returned early around line 68 when \considerContextUntrusted\ was \ rue, so it skipped the real Tool Result Policy evaluation around line 125 and returned empty \ oolResultUpdates.
Fix
Instead of returning early when \considerContextUntrusted\ is \ rue, we now:
This ensures that blocked tool results are properly replaced with [Content blocked by policy]\ before being sent to the model.
Test Plan
To reproduce the bug:
ead_issue\
Before fix: The raw tool result is sent in the model-facing LLM request.
After fix: The tool result is replaced with [Content blocked by policy]\ before being sent to the model.
/claim #4225