Cookbook
Raw Claude (no framework)
Screen a prompt before a Claude call, without a framework.
If you're calling the Anthropic client directly, screen the prompt yourself before the call. If Tawa blocks or leans toward blocking, the request is rejected without ever reaching Claude.
import os
from anthropic import Anthropic
from tawaguard import TawaGuard
anthropic = Anthropic(api_key=os.environ["ANTHROPIC_API_KEY"])
tawa = TawaGuard(os.environ["TAWA_API_KEY"])
_BLOCKED_ACTIONS = {"block", "hard_block", "soft_block"}
def chat(user_message: str):
scan = tawa.analyze(user_message)
if scan.action in _BLOCKED_ACTIONS or scan.suggestion == "block":
raise ValueError("Message blocked by content policy.")
return anthropic.messages.create(
model="claude-opus-5",
max_tokens=1024,
messages=[{"role": "user", "content": user_message}],
)