instructor icon indicating copy to clipboard operation
instructor copied to clipboard

Mode.BEDROCK_TOOLS missing from from_response parsing

Open aum-wmcginnis opened this issue 5 months ago • 2 comments

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.

aum-wmcginnis avatar Jul 18 '25 19:07 aum-wmcginnis

@claude please fix and make a PR

jxnl avatar Jul 18 '25 20:07 jxnl

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_TOOLS case to the from_response method at lines 220-221
  • Implemented Parser Method: Created parse_bedrock_tools method 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:

  1. Checks for incomplete output by comparing outputTokens with maxTokens
  2. Extracts content from Bedrock's nested response format (output.message.content)
  3. Filters for tool_use type content items
  4. Extracts the input field containing function arguments
  5. 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.


claude[bot] avatar Jul 18 '25 20:07 claude[bot]