Enforcing a policy
Policy directives are signals — here's how to actually act on them.
Every scan already carries the org's Policy Studio verdict
in result.policy — a matched rule's directives
("block", "disable_tools", ...) and matched_rule_ids. Activating a
built-in template or a custom rule in the dashboard's Policy Studio changes
what that field contains on every future scan. It does not, by itself,
change what happens to the request.
Tawa never blocks anything on its own. Every scan returns a verdict,
including result.policy — but your code decides what happens next.
Until your integration checks that field and acts on it, nothing about
your traffic changes.
Raw SDK
Check result.policy.directives yourself after any
analyze()/scan_context()/scan_chunk()/scan_tool_call()/scan_tool_output()
call, the same way you'd check result.action:
result = client.analyze(user_input)
if result.policy and "block" in result.policy.directives:
raise RuntimeError("Blocked by policy")OpenAI Agents SDK
tawa_input_guardrail()/tawa_output_guardrail()'s should_block is a
plain callback (default: default_should_block, which only looks at
result.action). Pass your own to also check result.policy:
from tawaguard.agents_sdk import default_should_block, tawa_input_guardrail
def policy_aware_should_block(result):
if result.policy and "block" in result.policy.directives:
return True
return default_should_block(result)
agent = Agent(
name="Assistant",
instructions="You are a helpful assistant.",
input_guardrails=[tawa_input_guardrail(tawa, should_block=policy_aware_should_block)],
)Full reference: OpenAI Agents SDK integration.