cognesy/instructor-php
Unified LLM API, structured data outputs with LLMs, and agent SDK - in PHP
What it solves
Instructor for PHP solves the problem of "messy" LLM outputs. Instead of manually parsing JSON or text, it allows developers to extract structured, validated data directly into typed PHP classes. It also provides a unified API to switch between dozens of LLM providers without rewriting connectivity code.
How it works
The library 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 prompting—to ensure the model returns data matching that schema. If the returned data fails validation (via 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 building AI-powered applications who need reliable, typed data from LLMs and want to avoid the brittleness of manual parsing and provider lock-in.
Highlights
- Structured Extraction: Turns LLM responses into typed PHP objects using various output modes (JSON, JSON Schema, Tools, and Markdown JSON).
- Unified Inference: A single API (Polyglot) that supports 20+ providers, including OpenAI, Anthropic, Gemini, Groq, and local models via Ollama.
- Self-Correction: Automated retries based on validation errors to improve response accuracy.
- Agent SDK: A lightweight framework for building tool-using agents with support for lifecycle hooks, subagents, and session management.
- Framework Agnostic: Works standalone or with first-party integrations for Laravel and Symfony.
- Multimodal Support: Capable of extracting structured data from both text and images.
관련
- 프로젝트
- 프로젝트
- 프로젝트
- 프로젝트
- 프로젝트