Instructor for PHP is a lightweight library that makes it easy to get structured outputs from Large Language Models (LLMs). Built on top of modern PHP 8.2+ features, it provides a simple, type-safe way to work with AI models.
<?phpuse Cognesy\Instructor\StructuredOutput;class Person { public string $name; public int $age; public string $occupation;}$text = "Extract: Jason is 25 years old and works as a software engineer.";$person = (new StructuredOutput) ->withResponseClass(Person::class) ->withMessages($text) ->get();echo $person->name; // "Jason"echo $person->age; // 25echo $person->occupation; // "software engineer"