Skip to content

fix: add run_in_parallel support to OutputGuardrail for sequential ex… - #4791

Open
Showmick119 wants to merge 2 commits into
openai:mainfrom
Showmick119:fix/output-guardrail-parallel
Open

fix: add run_in_parallel support to OutputGuardrail for sequential ex…#4791
Showmick119 wants to merge 2 commits into
openai:mainfrom
Showmick119:fix/output-guardrail-parallel

Conversation

@Showmick119

Copy link
Copy Markdown

This pull request adds support for sequentially executing output guardrails to match the behavior of input guardrails.

Previously, OutputGuardrail did not have a run_in_parallel flag and run_output_guardrails always executed all output guardrails concurrently. This meant it was impossible to run a fast, low-cost guardrail (e.g., regex checks) before a slow, expensive one (e.g., an LLM judge) to trip the wire early and save tokens/time.

  • Adds a run_in_parallel boolean field to OutputGuardrail (defaulting to True for backwards compatibility).
  • Updates the @output_guardrail decorator to accept run_in_parallel.
  • Modifies run_output_guardrails to partition sequential (run_in_parallel=False) and parallel guardrails, running the sequential ones in order before kicking off the concurrent ones. If a sequential guardrail trips, execution halts immediately.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5d570b4250

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/agents/guardrail.py
Comment on lines +159 to +161
run_in_parallel: bool = True
"""Whether the guardrail runs concurrently with other guardrails (True, default) or before
subsequent guardrails (False).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Honor sequential output guardrails in Realtime sessions

When these public guardrails are supplied through RealtimeAgent.output_guardrails or RealtimeRunConfig.output_guardrails, RealtimeSession._run_output_guardrails still awaits every guardrail in list order without consulting run_in_parallel (src/agents/realtime/session.py:1663-1669). Consequently, with an expensive default-parallel guardrail listed before a cheap run_in_parallel=False guardrail, the expensive check runs first and cannot be skipped when the cheap check trips—the exact cost-saving behavior this option promises works in Runner but is silently ignored on the supported Realtime path. Partition or otherwise honor the flag in that consumer as well.

AGENTS.md reference: AGENTS.md:L147-L147

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 50e1a5c498

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

triggered_results.append(result)
for t in tasks:
t.cancel()
break

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve all Realtime tripwire results

When two default-parallel Realtime output guardrails both trip, this break reports only the first result and ignores or cancels the others—even if multiple synchronous guardrail tasks have already completed. This regresses the public RealtimeGuardrailTripped.guardrail_results contract (documented as containing all triggered guardrails), and the follow-up message likewise omits their names; the pre-change caller-visible test explicitly covered both results. Preserve all parallel tripwire results before emitting the event while retaining the new sequential short-circuit behavior.

AGENTS.md reference: AGENTS.md:L147-L147

Useful? React with 👍 / 👎.

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.

1 participant