cognesy/instructor-php
Unified LLM API, structured data outputs with LLMs, and agent SDK - in PHP
What it solves
It eliminates the need to manually parse messy LLM outputs (like JSON or raw text) by turning them into typed, validated PHP data objects. It also solves the problem of provider lock-in by providing a unified API to interact with dozens of different LLM providers.
How it works
Instructor uses a "response model" (a plain PHP class with type-hints) to define the desired data structure. It then leverages LLM capabilities—such as native JSON mode, tool calling, or specific prompting—to force the model to return data matching that schema. If the output fails validation (using Symfony Validation), Instructor can automatically retry the request, feeding the validation errors back to the LLM so it can self-correct.
Who it’s for
PHP developers who want to integrate LLMs into their applications with type safety, structured data extraction, and the ability to switch between providers (e.g., OpenAI, Anthropic, Gemini, Ollama) without rewriting their core logic.
Highlights
- Structured Extraction: Converts text, images, or chat sequences into typed PHP classes.
- Automated Validation & Retries: Uses Symfony Validation to verify outputs and automatically retries failed requests with error feedback.
- Unified Inference (Polyglot): A single API layer supporting 20+ LLM providers, including local models via Ollama.
- Comprehensive AI Toolkit: Includes components for RAG (vector storage and retrieval), a lightweight Agent SDK for tool-using agents, and batch inference.
- Framework Agnostic: Works standalone or via first-party integrations for Laravel and Symfony.
Related
- Project
- Project
- Project
- Project
- Project