Mode.BEDROCK_TOOLS missing from from_response parsing
https://github.com/567-labs/instructor/blob/main/instructor/function_calls.py#L190
When using Mode.BEDROCK_TOOLS I get an exception here that object dict doesn't have attribute choices. It looks like it's missing from the if else ladder so is not parsed at all, Mode.BEDROCK_JSON seems to work.
@claude please fix and make a PR
Claude finished @jxnl's task —— View job
Analysis and Fix for Mode.BEDROCK_TOOLS Parsing Issue
Todo List:
- [x] Read repository guidelines (CLAUDE.md)
- [x] Investigate function_calls.py parsing logic around line 190
- [x] Identify how BEDROCK_JSON and other modes are handled
- [x] Implement fix for Mode.BEDROCK_TOOLS
- [ ] Run linting and type checking (requires Bash tool permission)
- [ ] Commit changes and create PR (requires Bash tool permission)
Issue Analysis:
Found that Mode.BEDROCK_TOOLS was missing from the if-else ladder in function_calls.py around line 190. The mode exists in mode.py and is supported by the bedrock client, but the response parsing was not implemented.
Solution Implemented:
- Added Mode Handler: Added
Mode.BEDROCK_TOOLScase to thefrom_responsemethod at lines 220-221 - Implemented Parser Method: Created
parse_bedrock_toolsmethod to handle Bedrock's tool response format - Error Handling: Includes proper handling for incomplete outputs and malformed responses
- AWS Bedrock Compliance: Works with the AWS Bedrock Converse API response structure
Implementation Details:
The parse_bedrock_tools method:
- Checks for incomplete output by comparing
outputTokenswithmaxTokens - Extracts content from Bedrock's nested response format (
output.message.content) - Filters for
tool_usetype content items - Extracts the
inputfield containing function arguments - Validates exactly one tool call and returns validated Pydantic model
Files Modified:
instructor/function_calls.py: Added missing Mode.BEDROCK_TOOLS handler and parse_bedrock_tools method
Status:
✅ Implementation Complete - The core fix has been implemented and follows existing patterns in the codebase.
⚠️ Pending Tasks - Need Bash tool permission to complete:
- Linting:
uv run ruff check instructor examples tests - Type checking:
uv run pyright - Git operations:
git add,git commit,git push
The implementation should resolve the issue where Mode.BEDROCK_TOOLS caused "object dict doesn't have attribute choices" errors, allowing proper structured output parsing for AWS Bedrock when using tool calling.