Repository navigation
fix(tools): tell the model when a RestApiTool body is empty or not JSON - #8097
Open
elmaroun07-hub wants to merge 1 commit into
Open
elmaroun07-hub wants to merge 1 commit into
elmaroun07-hub wants to merge 1 commit into
Conversation
When an API answered 2xx with an empty or non-JSON body, RestApiTool
returned only {"text": response.text}. An empty body reached the model as
{"text": ""}, which it cannot tell apart from real data.
Keep "text" as it is and add a "message" saying the body was empty or was
not valid JSON, with the status code. The call still counts as a success,
so nothing is reported under "error". JSON bodies and error statuses are
unchanged.
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.
Link to Issue or Description of Change
2. Or, if no issue exists, describe the change:
Problem:
When an API answers 2xx with a body that is empty or not valid JSON,
RestApiTool.callreturns only{"text": response.text}. With an empty body the model receives{"text": ""}and nothing tells it that the API returned no content, so it cannot distinguish "nothing came back" from data.Solution:
Keep
"text"exactly as it is and add one"message"key saying the body was empty, or was not valid JSON, with the status code. The call still counts as a success, so nothing is reported under"error"and_detect_error_in_responseis unaffected."message"is the key this file already uses for neutral notes ({"pending": True, "message": ...}). JSON responses and error statuses are unchanged.Testing Plan
Unit Tests:
openapi_toolfolder passes on four Python versions; the fulltoxrun did not finish on my machine.)Added to
test_rest_api_tool.py: empty body, whitespace-only body, HTML body, plain-text body, and a JSON body returned unchanged. Each test compares the whole returned dict. Before the fix: 4 failed, 1 passed. After: 5 passed.python -m pytest tests/unittests/tools/openapi_tool, run in each tox environment (Windows):Not completed: the full
toxrun. All four environments built, but the full suites were still running after 50 minutes on my Windows machine and I stopped them. Three pre-commit hooks (check-new-py-prefix,compliance-checks,check-docs) could not start under pre-commit on Windows; I ran their scripts directly and each exited 0.addlicensewas not installed locally. ruff, isort, pyink and codespell passed.Manual End-to-End (E2E) Tests:
Tool-level test: a local HTTP server on 127.0.0.1 and a direct
RestApiTool.callagainst it (not run throughadk webor a Runner).Checklist
openapi_toolfolder only, as above.)Additional context
If you would rather flag only the empty body and leave non-empty non-JSON bodies as they are, I can narrow the change.
I found this while measuring how agents respond when a tool returns an empty 200 body; in my runs with another framework, models often answered with made-up values instead of reporting it: https://github.com/elmaroun07-hub/reported-or-invented
This change was written with AI assistance (Claude Code); I reviewed and tested it.