Structured Output
Validate model JSON with AIOS Schema.
Structured output validates the model response against a JSON Schema before you read it.
Schema to validated JSON
Build a schema with "AIOS Schema", attach it to the request, then read validated JSON from the result:
Schema: Codeunit "AIOS Schema";
Fields: List of [JsonObject];
Request: Record "AIOS Chat Request";
Result: Codeunit "AIOS Generate Result";
begin
Fields.Add(Schema.Field('summary', Schema.String()));
Fields.Add(Schema.Field('score', Schema.Number()));
Request.SetPrompt('Score this customer feedback');
Request.SetOutput(Schema.Object(Fields));
Result := Client.GenerateText(Model, Request);
// Result.Output() is validated JSON text
end;
Result.Output() is validated JSON text, carrying exactly the fields the schema declared:
{
"summary": "Shipping was late, but support resolved it quickly.",
"score": 3.5
}Validation happens before you read it, so Result.Output() either matches the schema or the call errors. You never parse a half-formed response.
Flat RecRef convenience
For binding into a record:
Request.SetOutput(RecRef);
Result := Client.GenerateText(Model, Request, RecRef);
// JSON fills bindable fields; raw JSON remains on Result.Output()
Flat RecRef binding fills record fields from the validated JSON. Given the same two fields, the record comes back populated and the JSON is still on the result:
| Field | Value after the call |
|---|---|
Summary | Shipping was late, but support resolved it quickly. |
Score | 3.5 |
Use schema-validated JSON when you need a stable contract across versions.
With a tool loop, structured output and RecRef binding run on the final non-tool-call step only.