Repository navigation
fix(guardrails): accept Gemini-native tools without a type field - #42761
Parsiffall1 wants to merge 13 commits into
Conversation
|
| """Keep provider-native tools free of a synthetic ``type: null`` field.""" | ||
| data = handler(self) | ||
| if isinstance(data, dict) and data.get("type") is None: | ||
| data.pop("type", None) |
There was a problem hiding this comment.
data.pop(...) mutates the serialized dictionary, violating the repository requirement to construct values immutably. This requirement must be satisfied before merging
Context Used: CLAUDE.md (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| """A tool forwarded verbatim to the guardrail for inspection. | ||
|
|
||
| Built-in tools (code_interpreter, file_search, ...) have no ``function`` block | ||
| and stash their config in tool-specific keys, so only ``type`` is required and | ||
| ``extra="allow"`` preserves the rest instead of stripping it. | ||
| OpenAI-style tools carry a ``type`` (function / code_interpreter / file_search, | ||
| ...). Provider-native tools such as Gemini ``{"googleSearch": {}}`` have neither | ||
| ``type`` nor ``function``; ``extra="allow"`` keeps their keys intact so the | ||
| guardrail still sees the original payload. ``type`` is therefore optional. | ||
| """ |
There was a problem hiding this comment.
These explanatory docstrings, including the serializer and regression-test docstrings, violate the repository requirement limiting comments to necessary complex logic. Please resolve before merging
Context Used: CLAUDE.md (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
GuardrailToolParam required type: str, so payloads like {"googleSearch": {}}
failed validation under generic_guardrail_api / headroom with default_on and
surfaced as a 500 before the guardrail ran. Make type optional and omit a
null type on serialize so provider-native tools are forwarded verbatim.
Fixes BerriAI#42742
a2d9790 to
88bb3cd
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
438e49a to
b45175e
Compare
Merging this PR will not alter performance
|
…erializer The dict comprehension is not flagged by the mutable-collection rule, so the suppression comment suppressed nothing and tripped LIT013.
Trim explanatory docstrings on GuardrailToolParam and the Gemini-native tools regression test to match repo comment guidance.
|
Automatic reviews are disabled for this repository. |
|
Closing since #46338 covers this: |
What
Allow
GuardrailToolParamto accept provider-native tools that have notypefield (e.g. Gemini{"googleSearch": {}},{"codeExecution": {}}), and serialize them without injectingtype: null.Why
With
generic_guardrail_api/headroomanddefault_on: true, every request tool is validated viaGuardrailToolParam.model_validate. Gemini-native tools carry neithertypenorfunction, so Pydantic raisedtype Field requiredand the proxy returned a 500 before the guardrail ran.PR #31461 already covered OpenAI built-ins that have
typebut nofunction. This closes the remaining hole for provider-native shapes.How tested
TestToolSupport.test_gemini_native_tools_without_type_do_not_crashpytest tests/test_litellm/proxy/guardrails/guardrail_hooks/test_generic_guardrail_api.py::TestToolSupport— 2 passed (existing built-in tools case + new Gemini-native case)GenericGuardrailAPIRequest.model_dump(mode="json")forwards Gemini payloads verbatimFixes #42742