Turn any content into actionable data structures
Build robust AI-powered information processing with type safety, validation, and observability
Instructor is a framework-agnostic, developer-friendly PHP library that helps you obtain LLM inference results as structured, validated data.
Instructor simplifies LLM integration into your PHP application. It handles the complexity of extracting structured data from LLM outputs, allowing you to focus on building your application's logic and iterate faster. It supports multiple input types, including text, images, and OpenAI-style chat sequence arrays.
Turn LLM responses into type-safe data specified as PHP classes
Process input text, chat messages, images and get structured responses
Define response models statically as classes, or dynamically with structures or JSON Schema
Automatically validate LLM responses to get them self-corrected based on feedback
Dev friendly API, customizable behavior, minimal library footprint
Easily switch between LLM providers, choose between commercial or open source models
Works with any PHP framework (including Laravel and Symfony), easily embeddable
Pre-integrated support for OpenAI, Anthropic, Google, Cohere, Groq, and more
Detailed event system for monitoring, logging and debugging LLM interactions
Real-time partial updates to make your application more responsive and engaging
Unified API to generate vector embeddings via multiple providers
Unified API for context caching, reducing cost and time of inference
$ composer require cognesy/instructor-php
run.phpand use Instructor
1require __DIR__ . '/vendor/autoload.php'; 2 3use Cognesy\Instructor\Instructor; 4 5// Set up OpenAI API key 6$apiKey = 'your-openai-api-key'; 7putenv("OPENAI_API_KEY=" . $apiKey); 8// WARNING: In real project you should set up API key in .env file. 9 10// Step 1: Define target data structure(s)11class City {12 public string $name;13 public string $country;14 public int $population;15}16 17// Step 2: Use Instructor to run LLM inference18$city = (new Instructor)->withConnection('openai')->respond(19 messages: 'What is the capital of France?',20 responseModel: City::class,21);22 23var_dump($city);
run.php
$ php run.php
30+
Learn how to use Instructor - from basics to advanced topics.
60+
Instructor capabilities demonstrated in simple, runnable examples.
25+
Learn how to apply prompting techniques in your applications across various scenarios.
11
Choose from a variety of LLM API providers to power your Instructor applications.
"Instructor leverages the power Large Language Models to help you automate your business by turning any content sources into meaningful, actionable and structured records."
E-COMMERCE & RETAIL
E-COMMERCE & RETAIL
E-COMMERCE & RETAIL
CONTENT MANAGEMENT SYSTEMS
CONTENT MANAGEMENT SYSTEMS
CONTENT MANAGEMENT SYSTEMS
HEALTHCARE
HEALTHCARE
EDUCATION & E-LEARNING
EDUCATION & E-LEARNING
DIGITAL AGENCIES
DIGITAL AGENCIES
FINANCIAL SERVICES
FINANCIAL SERVICES
HOSPITALITY & TOURISM
HOSPITALITY & TOURISM
MANUFACTURING
MANUFACTURING
REAL ESTATE
REAL ESTATE
RECRUITMENT & HR
RECRUITMENT & HR