# Return a structured score from the AI SDK

> HasStructuredOutput defines a schema. The Vue page receives the fields you read from the response, not the provider payload.

- URL: https://laravel-vuejs.space/laravel-ai-structured-output-vue
- Author: Anass Ez-zouaine (https://laravel-vuejs.space/author/anass-ez-zouaine)
- Published: 2026-10-11
- Topics: Laravel, VueJs, Inertia

People searching “Laravel AI SDK structured output” print the whole provider response in Vue. Define a schema and pass one field. The [AI SDK guide](https://laravel-vuejs.space/laravel-ai-sdk-vue) is the text agent and the rule that the key stays on the server. This page is the schema.

> **TL;DR**
>
> -   HasStructuredOutput defines a schema.
> -   The Vue page receives the fields you read from the response, not the provider payload.
> -   Do not pass `$request->all()` to `prompt()`.
> -   Do not add a `VITE_` key so Vue can “check the score” with the provider.
>
> **Who it's for:** Laravel + Vue developers on Inertia
>
> **Applies to:** Laravel 13 · Inertia 3 · Vue 3

## The fix

```php
use Illuminate\Contracts\JsonSchema\JsonSchema;
use Laravel\Ai\Contracts\Agent;
use Laravel\Ai\Contracts\HasStructuredOutput;
use Laravel\Ai\Promptable;

class ScoreNote implements Agent, HasStructuredOutput
{
    use Promptable;

    public function instructions(): string
    {
        return 'Score the note from 1 to 5.';
    }

    public function schema(JsonSchema $schema): array
    {
        return [
            'score' => $schema->integer()->required(),
        ];
    }
}
```

```php
$response = (new ScoreNote)->prompt($validated['note']);

return Inertia::render('notes/Show', [
    'score' => $response['score'],
]);
```

The page prints `score`. It does not parse JSON.

## What to avoid

> **Gotcha**
>
> Do not pass `$request->all()` to `prompt()`. Do not add a `VITE_` key so Vue can “check the score” with the provider. The [AI SDK guide](https://laravel-vuejs.space/laravel-ai-sdk-vue) already refuses that.

## FAQ

**Q: How do I return a structured score from the AI SDK?**

HasStructuredOutput defines a schema. The Vue page receives the fields you read from the response, not the provider payload.

**Q: What goes wrong with Laravel AI SDK structured output?**

Many developers print the whole provider response in Vue. Do not pass `$request->all()` to `prompt()`.
