Skip to content

Using ANTHROPIC_TOOLS mode throws 400 from Anthropic API in 1.11.3 #1829

@Joehunk

Description

@Joehunk
  • This is actually a bug report.
  • I am not getting good LLM Results
  • I have tried asking for help in the community on discord or discussions and have not received a response.
  • I have tried searching the documentation and have not found an answer.

What Model are you using?

  • gpt-3.5-turbo
  • gpt-4-turbo
  • gpt-4
  • Other (please specify) Claude Sonnet 4

Describe the bug
We recently bumped our Instructor version from 1.10.0 -> 1.11.3. When using ANTHROPIC_TOOLS mode with an Anthropic model (I tried both Claude Sonnet 4 and 3.7), the following error is thrown:

<exception>
    Error code: 400 - {'type': 'error', 'error': {'type': 'invalid_request_error', 'message': 'messages.2: `tool_use` ids were found without `tool_result` blocks immediately after: toolu_01Tu9X18ypN9Q3tJgrppfVJa. Each `tool_use` block must have a corresponding `tool_result` block in the next message.'}, 'request_id': 'req_011CTf7ydPeSGSBovG3rxx3T'}
</exception>

There is a current bug against Anthropic with a similar error message, but our Anthropic SDK version did not change when we bumped Instructor versions.

For this bug to be hit, the first attempt at validating the model does appear to have to fail. If the model validation succeeds on the first try, this bug appears not to be hit.

To Reproduce
This code reproduces the error.

  1. Run test_with_instructor("My name is John Smith")
  2. Crash is observed.
  3. Change mode to ANTHROPIC_JSON or reduce Instructor version to 1.10.0
  4. Crash is no longer observed.
  5. Run with something that will succeed on the first try such as test_with_instructor("My name is Bob Smith")
  6. Crash is also no longer observed.

Expected behavior
Expected behavior is no crash, i.e. what happens in 1.10.0 or with ANTHROPIC_JSON mode.

Screenshots
NA

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions