← Back to Pull requests

feat(agent): add opt-in content safety checks for requests, tools, and output (T32) #177

Closed
unknown closed this pull request without merging on Oct 19, 2026 14:42 UTC
View on GitHub
unknown unknown commented on Oct 19, 2026 07:23 UTC
Author

Contributing to ARGI: add an opt-in content-safety pipeline for request ingress, tool arguments and results, and final output. Fixes #135.

Describe what this PR does / why we need it

PII detection on model text does not cover tool arguments, tool results, cached receipts, child results, return-direct payloads, or a secret split across streaming chunks. This PR adds an opt-in content-safety gate that applications compose onto the existing message hook, tool interceptor, and streaming interceptor. Default hooks, public APIs, and the default stream path are unchanged.

Does this pull request fix one issue?

Fixes #135

Describe how you did it

  • ContentSafetyGate checks configured stages (REQUEST_INGRESS, MODEL_EGRESS, TOOL_ARGS, TOOL_RESULT, FINAL_OUTPUT, RETURN_DIRECT, CHILD_RESULT, RECEIPT) and applies allow, block, redact, or require-review. Detector timeout and failure follow the configured policy and return a structured status. Audit and logs record stage, action, reason, and detector only.

  • ContentSafetyToolInterceptor checks arguments before dispatch. A blocked or require-review call is not dispatched. A redacted argument is dispatched only when ContentSafetyArgumentReview accepts it; otherwise the transform is rejected. Results, receipts, child results, and return-direct payloads are checked before an outer interceptor can persist them.

  • ContentSafetyModelHook applies the same stages to user, tool, child, receipt, and assistant messages, and drops blocked assistant tool calls. ContentSafetyStreamingInterceptor withholds an incomplete secret prefix and replaces a completed secret before release. require-review sets argi.contentSafety.review and does not add a new approval system.
  • Describe how to verify it

    ./mvnw -pl argi-agent-framework -am test -Dtest=ContentSafetyPipelineTest,ContentSafetyModelHookTest -DfailIfNoTests=false
    

    15 tests, 0 failures: tool arguments are checked when model text is clean and a block skips dispatch; PII in arguments is checked; tool result, receipt, child result, and return-direct share the configured check; an unreviewed argument transform is rejected; require-review does not dispatch; timeout and detector failure return a structured block status; audit text omits the payload; a secret split across chunks is not emitted; safe text after a blocked secret is released; a reviewed transform is dispatched.

    Special notes for reviews

    No new dependencies. Core does not import Redis or Extensions. Register the tool interceptor inside result eviction (later in the interceptor list) so persisted text is already checked.

    Diff: 331 lines (+248 / -83) across 4 files Reviewer: yuluo-yx Review duration: 439m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.42) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.42 · 331 lines diff across 4 files
    0.42
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.347
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #177"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 42.1% (MEDIUM) · Higher = larger blast radius
    42.1%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 16.6% · Safe to merge
    16.6%