Why Create a Custom Provider?
- Support new LLMs: Add providers for Claude, Cohere, Hugging Face, or any API
- Private deployments: Connect to internal model endpoints
- Independent distribution: Publish as a separate Python package
- Zero configuration: Auto-discovery via Python entry points
- Isolated dependencies: Keep provider-specific packages separate
Quick Start
Use the provider plugin generator to create a new provider in minutes:- Provider implementation
- Schema support (optional)
- Testing setup
- Package configuration
- Documentation
Architecture Overview
A provider plugin consists of:- Provider Class - Implements
BaseLanguageModelinterface - Registry Decorator - Registers model ID patterns
- Entry Point - Enables auto-discovery
- Schema Class (optional) - Enables structured output
Creating a Provider Plugin
Step 1: Package Structure
Create this directory structure:Step 2: Configure Entry Point
Inpyproject.toml:
Step 3: Implement Provider
Inlangextract_yourprovider/provider.py:
Step 4: Export Provider
Inlangextract_yourprovider/__init__.py:
Pattern Registration
The@register decorator defines which model IDs your provider handles:
Pattern Priority
- Default priority: 0 (first registered wins)
- Higher priority: Checked first (useful for overriding built-in providers)
- Explicit selection: Users can force a provider:
provider="YourProviderLanguageModel"
Adding Schema Support
Schema support enables structured output with strict JSON constraints.Step 1: Create Schema Class
Inlangextract_yourprovider/schema.py:
Step 2: Update Provider
Add schema support to your provider:Testing Your Provider
Createtests/test_provider.py:
Installation & Usage
Install in Development Mode
Use Your Provider
Publishing Your Provider
Build Package
Publish to PyPI
Share with Community
-
Test installation in clean environment:
-
Create documentation with:
- Supported model IDs and patterns
- Required environment variables
- Usage examples
- Provider-specific parameters
-
Share on GitHub:
- Open an issue on LangExtract GitHub
- Request addition to community providers list
Real-World Examples
See the complete examples:- Custom Provider Plugin Example - Full template with testing
- Built-in Providers - Study
langextract/providers/for reference implementations
Checklist
Setup (Required)
Setup (Required)
- Create package structure
- Configure
pyproject.tomlwith entry point - Implement provider class
- Add
@lx.providers.registry.register()decorator - Implement
__init__()method - Implement
infer()method - Export class from
__init__.py
Schema Support (Optional)
Schema Support (Optional)
- Create schema class inheriting
BaseSchema - Implement
from_examples()class method - Implement
to_provider_config()method - Add
get_schema_class()to provider - Handle schema in provider’s
infer()
Testing
Testing
- Install with
pip install -e . - Test basic inference
- Verify auto-discovery works
- Test schema support (if implemented)
- Test error handling
Documentation
Documentation
- Document supported model IDs
- List environment variables
- Provide usage examples
- Document provider-specific parameters
- Add installation instructions
Distribution
Distribution
- Test in clean environment
- Build package:
python -m build - Publish to PyPI:
twine upload dist/* - Share with community
Common Patterns
Environment Variable Fallback
Parallel Processing
Retry Logic
Troubleshooting
Plugin Not Loading
Pattern Not Matching
Check Registration
Next Steps
Provider Overview
Learn about the provider architecture
Gemini Provider
Study a production provider implementation
OpenAI Provider
See optional dependency handling
Ollama Provider
Learn about local provider patterns