trustcall  by hinthornw

Tool for reliable LLM tool calling with complex JSON schemas

created 1 year ago
819 stars

Top 44.2% on sourcepulse

GitHubView on GitHub
1 Expert Loves This Project
Project Summary

trustcall is a Python library designed to enhance the reliability and efficiency of LLM tool calling, particularly for complex JSON schema generation and updates. It addresses common LLM failures in producing structured output by prompting LLMs to generate JSON Patch operations for iterative correction, making it ideal for developers building robust LLM-powered applications.

How It Works

trustcall leverages LangGraph to manage a stateful, iterative process. When an LLM is asked to generate or update structured data, trustcall first prompts it to produce the output directly. If validation errors occur (e.g., with Pydantic models), it re-prompts the LLM to generate JSON Patch operations to correct the specific errors. This "patch-don't-post" approach is more resilient and cost-effective than regenerating the entire output. It also supports updating existing data structures by applying patches to provided schemas.

Quick Start & Requirements

  • Install: pip install trustcall
  • Prerequisites: Requires an LLM provider (e.g., OpenAI, Fireworks) with tool-calling capabilities. LangChain ecosystem compatibility is highlighted.
  • Documentation: Examples showcase usage with LangChain and LangGraph for extraction, updates, and agentic workflows.

Highlighted Details

  • Resilient Schema Generation: Handles complex, nested schemas defined via Pydantic, Python functions, or JSON schemas.
  • Efficient Updates: Modifies existing data structures by generating JSON Patches, preventing accidental data loss.
  • Simultaneous Inserts/Updates: Manages both creating new records and modifying existing ones from conversational data.
  • LangChain Integration: Works seamlessly with any tool-calling LLM from the LangChain ecosystem.

Maintenance & Community

The project appears to be actively maintained by hinthornw. Further community engagement details (e.g., Discord, Slack) are not explicitly mentioned in the README.

Licensing & Compatibility

The README does not explicitly state a license. Compatibility for commercial use or closed-source linking would require clarification on the licensing terms.

Limitations & Caveats

The README does not detail specific limitations, unsupported platforms, or known bugs. The effectiveness of the patch-based correction relies on the LLM's ability to accurately generate valid JSON Patches. Evaluation benchmarks are available but require additional dependencies and API keys.

Health Check
Last commit

2 weeks ago

Responsiveness

1 week

Pull Requests (30d)
5
Issues (30d)
4
Star History
145 stars in the last 90 days

Explore Similar Projects

Feedback? Help us improve.