-
Notifications
You must be signed in to change notification settings - Fork 19.7k
fix: Add bind_tools support to RunnableSequence for structured output chains #32175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
… chains This resolves issue langchain-ai#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 langchain-ai#28848 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
CodSpeed WallTime Performance ReportMerging #32175 will not alter performanceComparing
|
- 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.
CodSpeed Instrumentation Performance ReportMerging #32175 will not alter performanceComparing Summary
|
…ain-ai#32169) ## **Description:** This PR updates the internal documentation link for the RAG tutorials to reflect the updated path. Previously, the link pointed to the root `/docs/tutorials/`, which was generic. It now correctly routes to the RAG-specific tutorial page for the following text-embedding models. 1. DatabricksEmbeddings 2. IBM watsonx.ai 3. OpenAIEmbeddings 4. NomicEmbeddings 5. CohereEmbeddings 6. MistralAIEmbeddings 7. FireworksEmbeddings 8. TogetherEmbeddings 9. LindormAIEmbeddings 10. ModelScopeEmbeddings 11. ClovaXEmbeddings 12. NetmindEmbeddings 13. SambaNovaCloudEmbeddings 14. SambaStudioEmbeddings 15. ZhipuAIEmbeddings ## **Issue:** N/A ## **Dependencies:** None ## **Twitter handle:** N/A
- 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.
|
Could you re-submit this without updating any lockfiles are creating new test files? You will need to pull the latest changes from the repo. |
Done |
Summary
This PR resolves issue #28848 by adding
bind_tools()support toRunnableSequence, enabling the combination of structured output and tool binding.Problem
Users couldn't combine
with_structured_output()andbind_tools()because:with_structured_output()returns aRunnableSequenceRunnableSequencelacked abind_tools()methodSolution
Added an intelligent
bind_tools()method toRunnableSequencethat:Code Example
Technical Details
libs/core/langchain_core/runnables/base.pybind_tools()toRunnableSequenceclassbind_tools()Testing
test_sequence_bind_tools.pybind_toolsnot callable afterwith_structured_output#28848Impact
This enables critical AI application patterns like:
Fixes #28848