Skip to content

fix: 隔离 Guardrail 拦截后的原始结构化输出 - #59

Open
Shuhong-BNU wants to merge 10 commits into
limouren2000:mainfrom
Shuhong-BNU:fix/guardrail-output-containment
Open

fix: 隔离 Guardrail 拦截后的原始结构化输出#59
Shuhong-BNU wants to merge 10 commits into
limouren2000:mainfrom
Shuhong-BNU:fix/guardrail-output-containment

Conversation

@Shuhong-BNU

@Shuhong-BNU Shuhong-BNU commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

问题

当前 Agent Harness 会对完整 structured_output 执行输出 Guardrail 检查。

当 Guardrail 命中时,用户可见的 final_output 已经会替换为安全提示,但原始 structured_output 仍会:

  • 写入 AgentRun.structured_output
  • 通过 message.completed SSE 发送给前端

因此,被 Guardrail 拦截的内容仍可能通过持久化数据或结构化事件继续暴露。

修改

  • Guardrail 未命中时保持现有 structured output 行为
  • Guardrail 命中时不再持久化原始 blocked payload
  • message.completed 不再携带原始 blocked payload
  • 保留现有 guardrail.triggered、安全提示和 output_guardrail stop reason

本次修改只收紧 Guardrail 命中后的输出边界,不改变 Guardrail 检测规则。

测试

覆盖:

  • 安全 structured output 仍正常持久化并通过 SSE 返回
  • unsafe structured output 能触发 Guardrail
  • blocked payload 不写入 AgentRun.structured_output
  • blocked payload 不通过 message.completed SSE 暴露
  • 安全 fallback 和 output_guardrail stop reason 保持不变

实际执行:

  • Guardrail 定向测试:2 passed
  • 完整 API pytest:26 passed, 2 failed;两项失败均来自当前 upstream/main 的既有 API 测试问题(router.py 中未定义的 conversation,以及一项响应文案断言不一致)
  • PR 修改文件 Ruff:通过
  • py_compile:通过
  • git diff --check:通过

影响范围

本次仅修改 Agent Harness 的 Guardrail 输出处理和对应回归测试。

不修改:

  • Guardrail 检测规则
  • Tool Calling / Tool authorization
  • Provider
  • Memory
  • Context
  • Agent Step / Plan 状态语义

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants