fix(integ): make calculator tool more robust to LLM output variations#1445
Merged
yonib05 merged 1 commit intostrands-agents:mainfrom Jan 12, 2026
Merged
Conversation
The test_tool_use_with_structured_output test was flaky because the LLM sometimes uses '+' instead of 'add' as the operation string. The calculator tool now accepts both formats for all operations. Changes: - Accept both word and symbol forms: add/+, subtract/-, multiply/*, divide//, power/** - Also accept common abbreviations: sub, mul, div, pow - Normalize input with lower() and strip() - Fix divide operation (was b/a, now a/b) - Improve docstring with Args section This makes the integ tests more resilient to LLM output variations.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
dbschmigelski
approved these changes
Jan 12, 2026
Member
Author
✅ Approved & Ready to Merge!This PR has been approved by @dbschmigelski and all CI checks are passing! 🎉 Status Summary
What This FixesMakes the calculator integration test more robust by handling LLM output variations gracefully. Impact
Ready for merge when maintainers are available! 🦆 |
Merged
7 tasks
yonib05
approved these changes
Jan 12, 2026
manoj-selvakumar5
pushed a commit
to manoj-selvakumar5/strands-sdk-python
that referenced
this pull request
Feb 5, 2026
…strands-agents#1445) The test_tool_use_with_structured_output test was flaky because the LLM sometimes uses '+' instead of 'add' as the operation string. The calculator tool now accepts both formats for all operations. Changes: - Accept both word and symbol forms: add/+, subtract/-, multiply/*, divide//, power/** - Also accept common abbreviations: sub, mul, div, pow - Normalize input with lower() and strip() - Fix divide operation (was b/a, now a/b) - Improve docstring with Args section This makes the integ tests more resilient to LLM output variations. Co-authored-by: Strands Coder <strands-coder@users.noreply.github.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.
Description
Fixes a flaky integration test in
test_structured_output_agent_loop.pywheretest_tool_use_with_structured_outputwould fail intermittently.Root Cause
The LLM sometimes outputs
'+'instead of'add'as the operation string. The original calculator tool only accepted exact string matches like"add","subtract", etc., causing the function to return0when the LLM used symbols.Example of failure:
This was observed in PR #1444 CI run: https://github.com/strands-agents/sdk-python/actions/runs/20875011420/job/59982925582?pr=1444
Changes
add/+subtract/-/submultiply/*/muldivide///divpower/**/powlower()andstrip()b/a, nowa/bto match standard math notation)ArgssectionRelated Issues
Documentation PR
No documentation changes required - this is a test fixture.
Type of Change
Bug fix (test reliability)
Testing
'add'and'+'Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Created by strands-coder autonomous agent 🦆