Commits
Click on a commit to change the comparison rangefix: Add bind_tools support to RunnableSequence for structured output chains
This resolves issue #28848 where calling bind_tools() on a RunnableSequence
created by with_structured_output() would fail with AttributeError.
The fix enables the combination of structured output and tool binding,
which is essential for modern AI applications that need both:
- Structured JSON output formatting
- External function calling capabilities
**Changes:**
- Added bind_tools() method to RunnableSequence class
- Method intelligently detects structured output patterns
- Delegates tool binding to the underlying ChatModel
- Preserves existing sequence structure and behavior
- Added comprehensive unit tests
**Technical Details:**
- Detects 2-step sequences (Model < /dev/null | Parser) from with_structured_output()
- Binds tools to the first step if it supports bind_tools()
- Returns new RunnableSequence with updated model + same parser
- Falls back gracefully with helpful error messages
**Impact:**
This enables previously impossible workflows like ChatGPT-style apps
that need both structured UI responses and tool calling capabilities.
Fixes #28848
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com> style: Fix linting issues in RunnableSequence.bind_tools method
- Remove quoted type annotations
- Fix line length violations
- Remove trailing whitespace
- Use double quotes consistently
- Improve error message formatting for better readability
The S110 warnings about try-except-pass are intentional - we want
silent fallback behavior before raising the final helpful error. fix: Resolve all linting and type checking issues
- Replace broad Exception catching with specific exceptions (AttributeError, TypeError, ValueError)
- Add proper type annotations to test functions and variables
- Add type: ignore comments for dynamic method assignment in tests
- Fix line length violations and formatting issues
- Ensure all MyPy checks pass
All lint checks now pass successfully. The S110 warnings are resolved
by using more specific exception handling instead of bare try-except-pass.