Repository navigation
Conversation
Reviewer's GuideData structuresAdd
ImplementationTrack and restore unscanned suffixes as guards transform text, and add helpers to redistribute combined Anthropic redactions to their original text blocks.
Apply postflight redactions to the appropriate response fields, propagate per-block denials and strict evaluation errors, then mutate the response with the prepared redactions.
TestsAdd regression tests for independent Anthropic block redaction, cross-block matches, denial and failure handling, and scan-limit suffix preservation.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
PR Summary by QodoFix Anthropic postflight redaction across multiple content blocks
AI Description
Merge Risk
|
Code Review by Qodo
1.
|
There was a problem hiding this comment.
Hey - I've found 4 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="sdk/python/src/openlit/guard/_integration.py" line_range="357-360" />
<code_context>
+ continue
+ block_result = pipeline.evaluate(block.text, phase="postflight")
+ if (
+ block_result.action == GuardAction.REDACT
+ and block_result.transformed_text is not None
+ ):
+ block.text = block_result.transformed_text
+
+
</code_context>
<issue_to_address>
**Denied blocks reach callers**
When a per-block evaluation returns DENY while the combined evaluation does not, `_redact_anthropic_content_blocks` handles only `REDACT`, so `_apply_postflight` discards the block-level denial and returns the denied content without raising `GuardDeniedError`; the caller receives content the guard denied.
Propagate block-level `DENY` results by raising `GuardDeniedError` instead of returning the response.
</issue_to_address>
### Comment 2
<location path="sdk/python/src/openlit/guard/_integration.py" line_range="355" />
<code_context>
+ for block in content:
+ if not getattr(block, "text", None):
+ continue
+ block_result = pipeline.evaluate(block.text, phase="postflight")
+ if (
+ block_result.action == GuardAction.REDACT
</code_context>
<issue_to_address>
**Strict guard failures expose output**
When `fail_open` is false and an individual block evaluation raises after the combined evaluation succeeds, `pipeline.evaluate` raises, but `_apply_postflight`'s broad exception handler suppresses the error and returns the response, potentially partially redacted with remaining secrets visible to the caller.
Let per-block evaluation errors propagate when `fail_open` is false, without returning a partially processed response.
</issue_to_address>
### Comment 3
<location path="sdk/python/src/openlit/guard/_integration.py" line_range="355" />
<code_context>
+ for block in content:
+ if not getattr(block, "text", None):
+ continue
+ block_result = pipeline.evaluate(block.text, phase="postflight")
+ if (
+ block_result.action == GuardAction.REDACT
</code_context>
<issue_to_address>
**Split secrets remain unredacted**
When the combined Anthropic text matches a redaction but its individual text blocks do not, `_redact_anthropic_content_blocks` discards the combined evaluation's transformed text and applies only per-block results, so `_apply_postflight` returns the original blocks with the secret still visible to the caller.
Use the combined evaluation's transformed text when updating the content blocks instead of relying only on per-block results.
Also at `sdk/python/src/openlit/guard/_integration.py:356-360`.
</issue_to_address>
### Comment 4
<location path="sdk/python/src/openlit/guard/_integration.py" line_range="355-360" />
<code_context>
+ for block in content:
+ if not getattr(block, "text", None):
+ continue
+ block_result = pipeline.evaluate(block.text, phase="postflight")
+ if (
+ block_result.action == GuardAction.REDACT
+ and block_result.transformed_text is not None
+ ):
+ block.text = block_result.transformed_text
+
+
</code_context>
<issue_to_address>
**Long blocks lose their suffix**
When a text block is longer than the guard scan limit and a redaction match occurs within its scanned prefix, when a text block exceeds the scan limit and a redaction occurs within the scanned prefix, `Pipeline.evaluate` returns transformed text only for that prefix, and the helper assigns it over the full block. The response silently loses the remainder of that block.
Preserve the unscanned portion of each block when applying a prefix-only redaction, or avoid writing a truncated transformed result over the full block.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 4 findings to address first, and if a block is not redacted when it should be, its original text can be returned to the caller and any exposed data cannot be recalled by reverting. The change reevaluates each text block independently, so review should verify that redaction remains effective for every block.
Blocking findings: sdk/python/src/openlit/guard/_integration.py:360, sdk/python/src/openlit/guard/_integration.py:355, sdk/python/src/openlit/guard/_integration.py:355, sdk/python/src/openlit/guard/_integration.py:360
Raise on block-level DENY and strict evaluation errors, redistribute redactions to their original blocks, and carry transformed suffixes across guards with different scan limits without restoring already-redacted text. Co-Authored-By: Claude Sonnet 5 <[email protected]>
Issue number: #2021
Change description:
Anthropic postflight redaction joined all text content blocks into one string, redacted it once, and wrote the result only to the first block. Later blocks kept the original secret and the first block contained the duplicated conversation.
Fix:
_apply_postflight()now calls a new helper that runs the pipeline on each text block independently and writes each result back to its own block. A single-block response keeps the original combined path; DENY handling and thechoices/response.textbranches are unchanged.Checklist
Acknowledgment
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the project license.
Verification
New two-block regression test: base-red
['First: [REDACTED:email] Second: [REDACTED:email]', 'Second: [email protected]'](duplication + PII leak); with fix both blocks redacted independently. Target 1/1, module 17/17, guard suite 68/68 passed.py_compileand line-length check clean (pylintunavailable offline, not run).No live provider calls, network, or credentials — all HTTP/content is faked.
Summary by Sourcery
Fix Anthropic postflight redaction to safely transform each text content block without leaking or duplicating output.
Bug Fixes:
Enhancements:
Tests: