> ## Documentation Index
> Fetch the complete documentation index at: https://docs.instructorphp.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Optional fields

## Overview

Use PHP's nullable types by prefixing type name with question mark (?) to declare
component fields which are optional. Set a default value to prevent undesired
defaults like nulls or empty strings.

## Example

```php theme={null}
<?php
require 'examples/boot.php';

use Cognesy\Instructor\StructuredOutput;

class UserDetail
{
    public int $age;
    public string $firstName;
    public ?string $lastName;
}

$user = StructuredOutput::using('openai')
    ->withMessages('Jason is 25 years old.')
    ->withResponseClass(UserDetail::class)
    ->get();

dump($user);

assert(!isset($user->lastName) || $user->lastName === '');
?>
```
