Instructor for Laravel
Laravel integration for Instructor PHP — the structured output library for LLMs.Overview
Instructor for Laravel brings the full power of structured LLM output extraction into the Laravel ecosystem. Rather than parsing free-form text responses from language models, Instructor lets you define PHP classes that describe the data you need, and the package takes care of prompting the model, validating its response, and deserializing the result into typed objects. This package provides seamless integration between Instructor PHP and Laravel, giving you:- Laravel Facades — Use
StructuredOutput::,Inference::,Embeddings::, andAgentCtrl::facades for expressive, framework-native access to LLM capabilities. - Dependency Injection — Inject
StructuredOutput,Inference, orEmbeddingsdirectly into your classes through Laravel’s service container. - Testing Fakes — Mock LLM responses with
StructuredOutput::fake(),Inference::fake(),Embeddings::fake(), andAgentCtrl::fake(), complete with assertion helpers for verifying extraction calls, connection usage, and model selection. - Native Agent Runtime — Resolve native
Cognesy\Agentsregistries, loop factories, session runtime, broadcasting helpers, and telemetry wiring directly from Laravel’s container. - Laravel HTTP Client — All API calls go through Laravel’s
Http::client under the hood, which meansHttp::fake()works out of the box in your test suite. - Event Bridge — Instructor’s internal events are automatically dispatched through Laravel’s event system, so you can attach listeners, subscribers, and queued handlers with no extra wiring.
- Batteries Included Observability — Native agent broadcasting, telemetry projectors, and Laravel logging presets are wired through first-party config instead of app-local glue.
- Artisan Commands — Generate response model scaffolding with
make:response-model, verify your API configuration withinstructor:test, and bootstrap the package withinstructor:install. - Configuration Publishing — Laravel-style config file with environment variable support for all settings, from API keys and model selection to HTTP timeouts and logging presets.
- native
Cognesy\Agentsruntime integration underconfig('instructor.agents') - external CLI code agents via
AgentCtrlunderconfig('instructor.agent_ctrl')
Quick Start
1. Install the Package
2. Configure API Key
Add to your.env:
3. Extract Structured Data
Documentation
| Guide | Description |
|---|---|
| Installation | Detailed installation and setup instructions |
| Configuration | Complete configuration reference |
| Facades | Using StructuredOutput, Inference, Embeddings, and AgentCtrl facades |
| Native Agents | Terminology and config boundaries for native Cognesy\Agents integration |
| Response Models | Creating and using response models |
| Code Agents | Using AgentCtrl for Claude Code, Codex, and OpenCode |
| Testing | Testing with facade fakes plus native-agent helper utilities |
| Events | Event handling and Laravel integration |
| Commands | Artisan command reference |
| Advanced | Streaming, validation, and advanced patterns |
| Troubleshooting | Common issues and solutions |
Example: Complete Workflow
Requirements
- PHP 8.2+
- Laravel 10.x, 11.x, or 12.x