Feature Type
Nice to have
Feature Description
The docs already point to on_user_turn_completed for editing or dropping a user message before it reaches the LLM, and to llm_node for filtering generated content. What's missing is a runnable examples/ reference that shows a deterministic, code-level guard wired into those hooks, rather than relying on system-prompt instructions to hold the line (as the hotel_receptionist safety scenarios do today).
Concretely, an example under examples/ that:
- in
on_user_turn_completed, scans new_message and either strips the offending content or raises StopResponse() when a rule matches, and
- inside a
@function_tool, validates arguments and raises ToolError(...) when a tool call looks unsafe.
The detection itself can be any pattern engine — the value of the example is the wiring at the hook boundary, which carries over to voice/realtime agents where there's no separate proxy to inspect text. I'd use ATR (an open MIT detection ruleset with a small Python engine) for the matching, but the example would keep it swappable so it reads as a pattern, not a dependency.
If this seems in scope I'm happy to open a PR adding it under examples/, following the existing example layout and make check/make fix.
Disclosure: I maintain ATR.
Workarounds / Alternatives
Today the available patterns are documented (on_user_turn_completed, llm_node) but there's no end-to-end example, so users wire it up ad hoc. The hotel_receptionist scenarios cover safety through natural-language instructions, which is a different mechanism than a deterministic check.
Additional Context
Scope is intentionally small: one self-contained example, no framework changes, no new dependency in the core package.
Feature Type
Nice to have
Feature Description
The docs already point to
on_user_turn_completedfor editing or dropping a user message before it reaches the LLM, and tollm_nodefor filtering generated content. What's missing is a runnableexamples/reference that shows a deterministic, code-level guard wired into those hooks, rather than relying on system-prompt instructions to hold the line (as thehotel_receptionistsafety scenarios do today).Concretely, an example under
examples/that:on_user_turn_completed, scansnew_messageand either strips the offending content or raisesStopResponse()when a rule matches, and@function_tool, validates arguments and raisesToolError(...)when a tool call looks unsafe.The detection itself can be any pattern engine — the value of the example is the wiring at the hook boundary, which carries over to voice/realtime agents where there's no separate proxy to inspect text. I'd use ATR (an open MIT detection ruleset with a small Python engine) for the matching, but the example would keep it swappable so it reads as a pattern, not a dependency.
If this seems in scope I'm happy to open a PR adding it under
examples/, following the existing example layout andmake check/make fix.Disclosure: I maintain ATR.
Workarounds / Alternatives
Today the available patterns are documented (
on_user_turn_completed,llm_node) but there's no end-to-end example, so users wire it up ad hoc. Thehotel_receptionistscenarios cover safety through natural-language instructions, which is a different mechanism than a deterministic check.Additional Context
Scope is intentionally small: one self-contained example, no framework changes, no new dependency in the core package.