Repository navigation
fix: support synchronous guardrails inside running event loops - #149
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Nice work! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
Post-merge validation: merge-queue integration checks passed, and CI on main is also green: https://github.com/openai/openai-guardrails-python/actions/runs/40402499049 . The docs deployment fails during Setup uv because its cache glob expects an uncommitted uv.lock ( |
This pull request fixes synchronous Guardrails calls made while an event loop is already running, including notebooks and synchronous helpers invoked by async handlers. Both synchronous clients execute configured guardrails in a scoped worker with copied request context, while retaining the existing idle-loop behavior and tripwire/suppression semantics.
Synchronous Moderation fallback now constructs, uses and closes a native synchronous client inside its worker. Async-client and no-context fallback behavior stays the same. Custom checks that require caller-loop resources should use the asynchronous clients.
Addresses the scenario reported in #131. Includes real SDK contracts for OpenAI/Azure, Chat/Responses, streaming, repeated calls and tripwires, plus a repeated fallback check with a real loopback HTTP connection pool.
Validation: formatting, Ruff, mypy, pyright and the full test suite pass. Two consecutive independent adversarial review rounds were clean.