Commit f3f71f0
authored
Python: fix(bedrock): don't send toolChoice when no tools are configured (microsoft#5172)
* fix(bedrock): don't send toolChoice when no tools are configured
BedrockChatClient was sending toolConfig.toolChoice even when no tools
were configured (tools=None). AWS Bedrock requires toolConfig.tools to
be present whenever toolChoice is specified, causing a 400 validation
error.
Only set toolChoice when tool_config has a 'tools' key present.
Fixes microsoft#5165
Signed-off-by: bahtya <[email protected]>
* test: add tests for toolChoice without tools
- test_prepare_options_tool_choice_auto_without_tools_omits_tool_config
- test_prepare_options_tool_choice_required_without_tools_omits_tool_config
Verifies that toolConfig is omitted when tool_choice is set but no
tools are provided, preventing ParamValidationError from Bedrock.
* fix: address maintainer feedback — remove stray test file, raise ValueError for required without tools
1. Remove test_addition.py — stray duplicate of tests already in
python/packages/bedrock/tests/test_bedrock_client.py, missing all
necessary imports and would fail with NameError.
2. Change tool_choice='required' handling to raise ValueError when no
tools are configured instead of silently falling through. Using
'required' without tools is a logical contradiction — the model
must invoke a tool but none exist — so surfacing this as a
ValueError helps callers catch the misconfiguration early.
3. Update the corresponding test to expect ValueError instead of
silently omitted toolConfig.
---------
Signed-off-by: bahtya <[email protected]>1 parent ddfbdf5 commit f3f71f0
2 files changed
Lines changed: 40 additions & 3 deletions
Lines changed: 7 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
413 | 413 | | |
414 | 414 | | |
415 | 415 | | |
416 | | - | |
417 | | - | |
| 416 | + | |
| 417 | + | |
418 | 418 | | |
419 | | - | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
420 | 424 | | |
421 | 425 | | |
422 | 426 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
137 | 137 | | |
138 | 138 | | |
139 | 139 | | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
0 commit comments