---
title: 'Chain of Thought'
docname: 'chain_of_thought'
---

## Overview

This approach to "chain of thought" improves data quality, by eliciting LLM reasoning to
self-explain approach to generating the response.

> With Instructor you can achieve a 'modular' CoT, where multiple explanations
> can be generated by LLM for different parts of the response, driving a more
> granular control and improvement of the response.


## Example

```php
<?php
$loader = require 'vendor/autoload.php';
$loader->add('Cognesy\\Instructor\\', __DIR__.'../../src/');

use Cognesy\Instructor\Instructor;
use Cognesy\Instructor\Schema\Attributes\Instructions;

class Employee {
    #[Instructions('Think step by step to determine the correct year of employment.')]
    public string $reasoning;
    public int $yearOfEmployment;
    // ... other data fields of your employee class
}

$text = 'He was working here for 5 years. Now, in 2019, he is a manager.';

$employee = (new Instructor)->respond(
    messages: [['role' => 'user', 'content' => $text]],
    responseModel: Employee::class
);


dump($employee);

assert($employee->yearOfEmployment === 2014);
?>
```
