Skip to content

Conversation

jxnl
Copy link
Collaborator

@jxnl jxnl commented Jun 13, 2025

Fixes #1596

The reask_anthropic_json function was failing when Anthropic used extended thinking because it assumed response.content[0] was always a text block. With extended thinking, the first content can be a ThinkingBlock which doesn't have a .text attribute, causing AttributeError.

Solution

Fixed by filtering for text blocks similar to the pattern in function_calls.py:

  • Filter content by c.type == "text" to exclude ThinkingBlocks
  • Use the last text block for consistent behavior
  • Add fallback handling if no text blocks are found

Testing

The fix ensures compatibility with:

  • Regular Anthropic responses without thinking
  • Extended thinking responses with ThinkingBlocks
  • Mixed content responses

Generated with Claude Code


Important

Fixes reask_anthropic_json to handle ThinkingBlock by filtering for text blocks and adding fallback handling.

  • Behavior:
    • Fixes reask_anthropic_json in reask.py to handle ThinkingBlock by filtering for text blocks.
    • Uses the last text block for consistent behavior and adds fallback if no text blocks are found.
  • Compatibility:
    • Ensures compatibility with regular Anthropic responses, extended thinking responses, and mixed content responses.

This description was created by Ellipsis for 7e66231. You can customize this summary. It will automatically update as commits are pushed.

The reask_anthropic_json function was failing when Anthropic used extended thinking because it assumed response.content[0] was always a text block. With extended thinking, the first content can be a ThinkingBlock which doesn't have a .text attribute, causing AttributeError.

Fixed by filtering for text blocks similar to the pattern in function_calls.py:
- Filter content by c.type == "text" to exclude ThinkingBlocks
- Use the last text block for consistent behavior
- Add fallback handling if no text blocks are found

Fixes #1596

Co-authored-by: Jason Liu <[email protected]>
Copy link

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
instructor 7e66231 Commit Preview URL Jun 12 2025, 11:56 PM

@github-actions github-actions bot added bug Something isn't working python Pull requests that update python code size:M This PR changes 30-99 lines, ignoring generated files. labels Jun 13, 2025
Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

Looks good to me! 👍

Reviewed everything up to 7e66231 in 34 seconds. Click for details.
  • Reviewed 24 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 2 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. instructor/reask.py:76
  • Draft comment:
    Good handling of non-text blocks. Consider logging a warning when no text blocks are found to aid debugging in unexpected cases.
  • Reason this comment was not posted:
    Confidence changes required: 66% <= threshold 85% None
2. instructor/reask.py:82
  • Draft comment:
    Using the last text block is reasonable, but the comment referencing 'function_calls.py:396-397' might become outdated. Consider describing the strategy instead of referring to line numbers.
  • Reason this comment was not posted:
    Confidence changes required: 40% <= threshold 85% None

Workflow ID: wflow_ycy1huyeJ1pbjgbN

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

@jxnl jxnl merged commit af04d30 into main Jun 13, 2025
16 of 17 checks passed
@jxnl jxnl deleted the claude/issue-1596-20250612_234805 branch June 13, 2025 01:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working python Pull requests that update python code size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

reask_anthropic_json doesn't work with Anthropic extended thinking

1 participant