Back to catalog / Agent safety
Intercept or redact content in a live bidirectional agent session
Inspect content before it reaches a live model stream and block or replace the turn when needed.
Goal
Add content filtering and redaction to live interaction so blocked content does not reach the model.
Steps
- Define input/output segments to inspect, blocking policy, and user-facing notice. [live]
- Use
LlmAgent.before_model_callback/after_model_callbackor correspondingBasePlugincallbacks; define when to return a replacementLlmResponse. [live] - Return a replacement response or end the turn for policy-triggering content so the original is not sent onward. [live]
- Test allowed, redacted, and rejected cases; ensure callbacks do not copy secrets into logs. [live]
How to verify
Blocked segments do not reach later model calls, allowed content continues, and audit logs omit sensitive payloads.
Troubleshooting
If a turn continues after replacement, verify the callback return and termination semantics; disable export first if logs leak data.
Permissions
Prerequisites
- Python 3.11+, google-adk compatible with the pinned revision, and an isolated test environment
- Configured model-provider credentials for live inference; never place them in code or logs
Permissions
- Use authorized test data only; isolate sessions and credentials per user; obtain human authorization before external side effects
Limitations
This procedure follows Google ADK at the pinned revision; other versions, models, or remote services may differ in APIs and event semantics. Recheck permissions, retention, and recovery before production.
Pinned upstream source
- Repository
- google/adk-python
- File path
- docs/guides/flows/llm_flows/base_llm_flow/live_model_callbacks.md
- Pinned commit
e9b74d36140f2594b24c481fb7a3825b2cb01e96- Source checked
- 2026-10-14 · Reviewed against the pinned upstream source
Repository metrics
These values describe the upstream repository, not popularity or likes for an individual skill or playbook.
- Stars
- Not collected
- Forks
- Not collected
- Observed at
- Not collected
No metrics snapshot is available yet.
License: Apache-2.0
Main topic
Make Agent behavior safer and easier to verify