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()toprompt(). - Do not add a
VITE_key so Vue can “check the score” with the provider.
The fix#
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(),
];
}
}$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().



