Skip to main content

A Python library that uses LLMs to diagnose and explain exceptions

Project description

LLM Catcher

LLM Catcher is a Python library that uses Large Language Models to diagnose and explain exceptions in your code.

Features

  • Exception diagnosis using LLMs
  • Both synchronous and asynchronous APIs

Installation

pip install llm-catcher

Quick Start

  1. Create a .env file with your OpenAI API key:
LLM_CATCHER_OPENAI_API_KEY=your-api-key-here

Examples

The examples/ directory contains several examples demonstrating different use cases:

1. Minimal Example (examples/minimal.py)

  • Basic usage with direct LLM exception diagnosis
  • Shows how to set up the diagnoser
  • Demonstrates basic error handling and diagnosis

2. FastAPI Integration (examples/fastapi_example.py)

  • Shows how to integrate LLM Catcher with FastAPI
  • Demonstrates how to handle exceptions in FastAPI
  • Includes a Swagger UI endpoint for testing

Run any example like this:

# Run minimal example
python examples/minimal_example.py

# Run FastAPI example
python examples/fastapi_example.py
# Then visit http://localhost:8000/docs

Each example includes detailed comments and demonstrates best practices for using LLM Catcher in different contexts.

Configuration

All settings can be configured through environment variables or the Settings class:

Complete Settings Example

from llm_catcher.settings import get_settings

settings = get_settings()

# Required
settings.openai_api_key = "your-api-key"  # Or set via LLM_CATCHER_OPENAI_API_KEY

# Model Settings
settings.llm_model = "gpt-4"  # Options: "gpt-4", "gpt-3.5-turbo", "gpt-4-1106-preview"
settings.temperature = 0.2  # Range: 0.0-1.0

Environment Variables

The same settings can be configured via environment variables:

# Required
LLM_CATCHER_OPENAI_API_KEY=your-api-key-here

# Model Settings
LLM_CATCHER_LLM_MODEL=gpt-4
LLM_CATCHER_TEMPERATURE=0.2

Settings Reference

Setting Type Default Description
openai_api_key str None Your OpenAI API key (required)
llm_model str "gpt-4" LLM model to use
temperature float 0.2 Model temperature (0.0-1.0)

Development

Setup Development Environment

# Clone the repository
git clone https://github.com/yourusername/llm-catcher.git
cd llm-catcher

# Create and activate virtual environment
python -m venv venv
source venv/bin/activate  # Linux/Mac
# or
.\venv\Scripts\activate  # Windows

# Install development dependencies
pip install -e ".[dev]"  # This installs the package with development extras

Notes

  • API key is required and must be provided via environment or settings
  • Settings are validated on initialization
  • Stack traces are included in LLM prompts for better diagnosis

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llm_catcher-0.3.0.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llm_catcher-0.3.0-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file llm_catcher-0.3.0.tar.gz.

File metadata

  • Download URL: llm_catcher-0.3.0.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.10

File hashes

Hashes for llm_catcher-0.3.0.tar.gz
Algorithm Hash digest
SHA256 e126727f342d821ffe36184fdba960289a9125e97c088d0d8b2b87097cff75a1
MD5 db775a6058b96f61ec51c82f19e93f04
BLAKE2b-256 4391661f85cb9fdc38f34fdc053f0d9b600713c046a699fd7b621a8e523ebcfe

See more details on using hashes here.

File details

Details for the file llm_catcher-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: llm_catcher-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.10

File hashes

Hashes for llm_catcher-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 509cb1c9b5bc380908c1cd3d8c7c07ae53d34e2d7b142c30a4a53e948b5ffc25
MD5 0d1b00bdc25455eb9d49c76c0b2fbb96
BLAKE2b-256 24b5932b77f25cc3737b3237bf52ee2c89b7aaaea64cc44248b454b177915c99

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page