Google GenAI integration throws Pydantic ValidationError (Extra inputs are not permitted for max_tokens) #2177
Replies: 1 comment
|
Thanks for providing the patch! This is a textbook example of provider parameter leakage across abstractions. The core issue is that LangChainLLMAdapter passes generic parameter payloads directly down to provider-specific configuration builders (GenerateContentConfig). Because Google's modern SDK strictly enforces extra="forbid", receiving max_tokens instead of max_output_tokens causes Pydantic to raise a ValidationError at runtime. While the monkey-patch works as a temporary hotfix, a proper long-term solution requires: This dynamic parameter mismatch is exactly why engineering high-availability AI agent engines in loosely-typed ecosystems requires constant patching—and why engines like OpenTron move these contracts to strongly-typed compile-time interfaces (Java 21) so schema drift never hits production. OpenTron is a production-ready, stateful multi-agent orchestrator written natively on Java 21, Spring Boot, and PostgreSQL.
|
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Bug: Google GenAI integration throws Pydantic ValidationError (Extra inputs are not permitted for max_tokens)
Description
When using NeMo Guardrails with the modern
google_genaiengine orlangchain-google-genaiwrappers (targeting models likegemini-2.5-flash), internal sub-actions such asself_check_inputorself_check_outputfail during execution.The underlying Google GenAI SDK strictly enforces input validation via Pydantic (
GenerateContentConfig) and prohibits unmapped keys (extra="forbid"). NeMo Guardrails appears to explicitly force a hardcodedmax_tokenspayload property into internal LLM invocation calls, causing the validation schema to reject the request and crash the application runtime.Steps to Reproduce
config.ymlto target a Google Gemini model:Run any standard greeting or message query to hit the active guardrail lifecycle loop.
Observe the crash dump occurring directly inside nemoguardrails/actions/llm/utils.py.
Expected Behavior
The parameter should either be automatically stripped when interfacing with Google GenAI providers or remapped dynamically to Google's accepted naming token key: max_output_tokens.
Actual Error Stack Trace
Environment Details
NeMo Guardrails Version: [0.23.0]
Python Version: [3.13]
Operating System: Windows
Temporary Workaround (For Anyone Facing This)
For those hitting this block right now, you can try using this patch for google engine
All reactions