Fail fast when tool is missing input_schema in function calling#4779
Fail fast when tool is missing input_schema in function calling#4779ohltyler wants to merge 4 commits intoopensearch-project:mainfrom
Conversation
PR Reviewer Guide 🔍(Review updated until commit 3fa81f5)Here are some key observations to aid the review process:
|
Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>
PR Code Suggestions ✨Latest suggestions up to 3fa81f5 Explore these optional code suggestions:
Previous suggestionsSuggestions up to commit 3a1a733
Suggestions up to commit 7b8e6c5
Suggestions up to commit a5cbfb0
Suggestions up to commit 07c7e88
Suggestions up to commit 4a8f5a2
|
|
Persistent review updated to latest commit 7a63fd6 |
This reverts commit 7a63fd6.
|
Persistent review updated to latest commit 4a8f5a2 |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4779 +/- ##
=========================================
Coverage 77.40% 77.40%
- Complexity 11900 11905 +5
=========================================
Files 963 963
Lines 53310 53311 +1
Branches 6500 6500
=========================================
+ Hits 41266 41268 +2
+ Misses 9287 9286 -1
Partials 2757 2757
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| toolParams.put(DESCRIPTION, StringEscapeUtils.escapeJson(tool.getDescription())); | ||
| Map<String, ?> attributes = tool.getAttributes(); | ||
| if (attributes == null || !attributes.containsKey("input_schema")) { | ||
| toolParams.put("attributes.input_schema", "{\"type\":\"object\",\"properties\":{}}"); |
There was a problem hiding this comment.
Can we create constants for both key and value
There was a problem hiding this comment.
Done — extracted both into INPUT_SCHEMA and DEFAULT_INPUT_SCHEMA constants, and replaced all 5 occurrences of the "input_schema" string literal in the file.
Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>
|
Persistent review updated to latest commit 7b8e6c5 |
|
This can lead to silent failures where the agent attempts to trigger the tool using the "default" input schema but might fail as the tool expects a different input schema. This failure would never be surfaced to the user. I agree that some validation could be added and error messages cleaned up. With that said, why not just set the input_schema during agent register? You can override the input_schema today, example: https://github.com/Jon-AtAWS/opensearch-ml-quickstart/blob/5bf3bdbd0fcb71842be7a3f91c7e72894fd626bb/examples/agent_tools.py#L49 |
|
Persistent review updated to latest commit 3a1a733 |
Instead of silently injecting an empty default schema when a tool is missing input_schema, throw IllegalArgumentException with a message naming the tool and the missing attribute. A default empty schema misleads the LLM into calling the tool with no arguments, causing silent failures downstream. Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>
3a1a733 to
3fa81f5
Compare
|
Persistent review updated to latest commit 3fa81f5 |
@pyek-bot thought about this more, I agree that the silent failure is also not ideal. I've updated the PR to just throw an exception if the input schema is missing. I separately added default input schemas for the tools that we were using when testing agentic search with the vectordb tool here: opensearch-project/skills#722 Setting input schema during register is always an option, but not a good user experience and very error prone. |
|
@ohltyler Thanks for adding the Regarding the exception, what happens now if a tool is registered without |
Description
When a conversational agent builds the function calling payload (e.g., for Bedrock Converse or OpenAI), each tool must have an
input_schemaattribute so the LLM knows what parameters to pass. Ifinput_schemais missing, the${tool.attributes.input_schema}placeholder is left unresolved, producing invalid JSON that the LLM provider rejects with an opaqueInvalid payloaderror.Fix
Throw a clear
IllegalArgumentExceptioninAgentUtils.addToolsToFunctionCalling()when a tool is missinginput_schema, naming the tool and the missing attribute. This fails fast with an actionable error message instead of producing silent failures.Tools should define
input_schemaeither:Testing
input_schema— both verify the exception is thrown with the correct tool name and attribute nametestAddToolsToFunctionCallingupdated to includeinput_schemain mock tool attributesIssues Resolved
N/A - discovered during investigation of VectorDBTool support for agentic search