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.

For your AI agent

Copies a prompt. Paste it into the AI agent you already have open.

Read https://laravel-vuejs.space/laravel-ai-structured-output-vue.md
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.
Show the diff. Do not commit.
On this page · 3 sections
  1. The fix
  2. What to avoid
  3. FAQ

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 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 already refuses that.

FAQ#

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.

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().

Found this useful?

Ask questions, share what you built.

Join thousands of Laravel and Vue developers in our Facebook group, or get new posts in your Telegram feed. Sharing this article helps too.

Keep reading

Newsletter

Get the best of Laravel & Vue, once a month.

One short email with new guides, release notes worth reading and hand-picked community links. No spam, unsubscribe any time.