fix(terminal): remap 'commands' alias to 'command' for google/gemma-4#3741
Draft
jeffmay wants to merge 1 commit into
Draft
fix(terminal): remap 'commands' alias to 'command' for google/gemma-4#3741jeffmay wants to merge 1 commit into
jeffmay wants to merge 1 commit into
Conversation
google/gemma-4 models consistently emit "commands" (plural) as the terminal tool's argument name instead of the correct "command" (singular), causing every shell invocation to fail with a Pydantic validation error. A mode='before' model_validator on TerminalAction silently remaps the wrong key before validation so the error path is never reached. This is intentionally placed on the model rather than in fix_malformed_tool_arguments because the two utilities address different problems: fix_malformed_tool_arguments corrects wrong VALUE types (JSON- encoded strings, chunked lists); a model_validator is the right layer for wrong KEY names, keeping each concern co-located with what it describes. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
I was experiencing issues with Gemma 4 attempting to use the Bash tool with a
commandsinput, when the tool expectscommand. At first, I solved this by just adding the note that the bash tool should usecommandinstead, but this eats up tokens in the context and is not always followed by the AI. This solution is a potential fix that I am contributing back in case anyone else if having this issue, but I am unfamiliar with the work in this repo and whether this is the correct solution. On the surface, it doesn't seem to break anything and doesn't add to the cost, so it feels worth including, but if there is a cleaner way to achieve the same effect, I would be happy to review, test, and promote the changes.Why a
model_validatoronTerminalActionand notfix_malformed_tool_arguments?The existing
fix_malformed_tool_argumentsutility (and its recent additions for GLM 4.6 and minimax-m2.5) corrects wrong value types — JSON-encoded strings for list/dict fields, or lists of string chunks for str-only fields. The Gemma 4 issue is a different category: a wrong key name. Mixing key-name remapping into the value-coercion utility would blur that boundary.A
model_validator(mode="before")on the model is the idiomatic Pydantic solution for field-level aliasing and is co-located with the field it protects, making the intent obvious to future readers. It also composes correctly with the existing literal-argument detection logic that runs at validation time.Summary
google/gemma-4models consistently emit"commands"(plural) as theterminaltool's argument name instead of the correct"command"(singular), causing every shell invocation to fail with a PydanticValidationErrorbefore the command is ever executed.mode='before'model_validatoronTerminalActionthat silently remaps the wrong key to the correct one so validation always succeeds for this known mismatch.Issue Number
How to Test
Automated Tests
tests/tools/terminal/test_terminal_tool.py::test_terminal_action_commands_alias_remapped— verifies"commands"is accepted and mappedtests/tools/terminal/test_terminal_tool.py::test_terminal_action_command_canonical_unchanged— verifies"command"still workstests/tools/terminal/test_terminal_tool.py::test_terminal_action_command_takes_precedence_over_commands— verifies no regression when both keys appearManual Test
openrouter/google/gemma-4-31b-it:freemodel to execute a bash command and verify that it uses the correct{ "input_value" { "command": ... }, ...}field name.Video/Screenshots
Type
Notes
🤖 Generated with Claude Code