Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aim Security post-call guardrails support #8356

Conversation

hxtomer
Copy link
Contributor

@hxtomer hxtomer commented Feb 7, 2025

Title

This PR adds support for post-call Aim Security guardrails. Aim guards can analyze LLM output in streaming mode using websockets, in order to ensure a smooth user experience while securing the streamed content with increasing context rather than processing it chunk by chunk.

Type

🆕 New Feature

Changes

I've added a new CustomGuardrail hook that allows Guardrails to consume the response stream as an iterator instead of chunk by chunk. An example usage is in aim.py.

[REQUIRED] Testing - Attach a screenshot of any new tests passing locally

If UI changes, send a screenshot/GIF of working UI fixes

image
Tested on python 3.9 - 3.12 (3.8 seems to have some dependency issues at the moment).

Thanks in advance for your review :)

Tomer

Copy link

vercel bot commented Feb 7, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
litellm ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 13, 2025 7:07am

@hxtomer
Copy link
Contributor Author

hxtomer commented Mar 10, 2025

Hi @ishaan-jaff, just wanted to check in if you've had a chance to look at this yet. Thanks!

@krrishdholakia krrishdholakia changed the base branch from main to litellm_dev_03_12_2025_contributor_prs_p2 March 13, 2025 05:55
@krrishdholakia
Copy link
Contributor

Hey @hxtomer your branch has merge conflicts with the dev branch - can you please resolve and let me know?

Happy to help merge this in

hxtomer added 4 commits March 13, 2025 08:53
CR

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@hxtomer
Copy link
Contributor Author

hxtomer commented Mar 13, 2025

Hey @krrishdholakia, thanks for putting the effort on this. I fixed the conflicts and avoided the perf issue by whether each guardrail actually needs to register async_post_call_streaming_iterator_hook, reducing the footprint to near zero. It will also improve stacktraces readability (as only the relevant iterator will be included, and not all of them).
Thanks!

@@ -21,6 +21,7 @@ Documentation = "https://docs.litellm.ai"
[tool.poetry.dependencies]
python = ">=3.8.1,<4.0, !=3.9.7"
httpx = ">=0.23.0"
websockets = "^13.1.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @hxtomer this is not needed. your file is a proxy guardrail. This would make it a dep on the basic pip package.

add it under proxy= on line 56

@krrishdholakia krrishdholakia merged commit a2414d0 into BerriAI:litellm_dev_03_12_2025_contributor_prs_p2 Mar 13, 2025
3 checks passed
@hxyannay hxyannay deleted the feature/aim-post-call branch March 13, 2025 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants