docs: document streaming iterator guardrail

This commit is contained in:
Krrish Dholakia
2025-03-22 20:20:36 -07:00
parent d0e022cfac
commit f90b8a4955
2 changed files with 16 additions and 1 deletions
+1 -1
View File
@@ -240,7 +240,7 @@ model_list:
```bash
litellm --config /path/to/config.yaml --detailed_debug
# RUNNING ON http://0.0.0.0:4000
# RUNNING ON http://0.0.0.0:4000
```
3. Test it!
@@ -128,6 +128,21 @@ class myCustomGuardrail(CustomGuardrail):
):
raise ValueError("Guardrail failed Coffee Detected")
async def async_post_call_streaming_iterator_hook(
self,
user_api_key_dict: UserAPIKeyAuth,
response: Any,
request_data: dict,
) -> AsyncGenerator[ModelResponseStream, None]:
"""
Passes the entire stream to the guardrail
This is useful for guardrails that need to see the entire response, such as PII masking.
See Aim guardrail implementation for an example - https://github.com/BerriAI/litellm/blob/d0e022cfacb8e9ebc5409bb652059b6fd97b45c0/litellm/proxy/guardrails/guardrail_hooks/aim.py#L168
"""
async for item in response:
yield item
```