Skip to content

fix(guardrails): accept Gemini-native tools without a type field - #42761

Closed
Parsiffall1 wants to merge 13 commits into
BerriAI:mainfrom
Parsiffall1:fix/guardrail-gemini-native-tools
Closed

Parsiffall1 wants to merge 13 commits into
BerriAI:mainfrom
Parsiffall1:fix/guardrail-gemini-native-tools

Conversation

@Parsiffall1

Copy link
Copy Markdown

What

Allow GuardrailToolParam to accept provider-native tools that have no type field (e.g. Gemini {"googleSearch": {}}, {"codeExecution": {}}), and serialize them without injecting type: null.

Why

With generic_guardrail_api / headroom and default_on: true, every request tool is validated via GuardrailToolParam.model_validate. Gemini-native tools carry neither type nor function, so Pydantic raised type Field required and the proxy returned a 500 before the guardrail ran.

PR #31461 already covered OpenAI built-ins that have type but no function. This closes the remaining hole for provider-native shapes.

How tested

  • Added TestToolSupport.test_gemini_native_tools_without_type_do_not_crash
  • Ran pytest tests/test_litellm/proxy/guardrails/guardrail_hooks/test_generic_guardrail_api.py::TestToolSupport — 2 passed (existing built-in tools case + new Gemini-native case)
  • Also verified GenericGuardrailAPIRequest.model_dump(mode="json") forwards Gemini payloads verbatim

Fixes #42742

@Parsiffall1
Parsiffall1 requested a review from a team September 23, 2026 17:35
@Parsiffall1
Parsiffall1 deleted the fix/guardrail-gemini-native-tools branch September 23, 2026 17:38
@greptile-apps

greptile-apps Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

The functional change appears sound, but the outstanding repository-rule violations must be resolved before merging.

Findings

  1. P2 In-place mutation added ▶
  2. P2 Unnecessary docstrings added ▶

Summary

Makes the generic guardrail tool model accept provider-native tool payloads without a type field and omit the synthetic null field during serialization.

  • Changes GuardrailToolParam.type to an optional field.
  • Adds serialization behavior that preserves provider-native payload shapes.
  • Adds regression coverage for Gemini-native search and code-execution tools.

Reviews (2) · Last reviewed commit: "fix(guardrails): accept Gemini-native to..."

"""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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 In-place mutation added

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!

Comment on lines 16 to 22
"""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.
"""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Unnecessary docstrings added

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
@Parsiffall1
Parsiffall1 restored the fix/guardrail-gemini-native-tools branch September 23, 2026 17:41
@Parsiffall1 Parsiffall1 reopened this Sep 23, 2026
@cursor
cursor Bot force-pushed the fix/guardrail-gemini-native-tools branch 2 times, most recently from a2d9790 to 88bb3cd Compare September 23, 2026 17:46
@codecov

codecov Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@cursor
cursor Bot force-pushed the fix/guardrail-gemini-native-tools branch from 438e49a to b45175e Compare September 23, 2026 17:56
@codspeed

codspeed Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

⚠️ 1 benchmark spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

✅ 31 untouched benchmarks


Comparing Parsiffall1:fix/guardrail-gemini-native-tools (e12a89f) with main (694582a)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (3740d48) during the generation of this report, so 694582a was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@greptile-apps

greptile-apps Bot commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Automatic reviews are disabled for this repository.

@Parsiffall1

Copy link
Copy Markdown
Author

Closing since #46338 covers this: GuardrailToolParam.type is now optional and left off the wire when absent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant