feat: first-class structured output support in AiClient - #4
Merged
Conversation
Expose chatStructured() on the AiClient facade so features can request validated JSON without hand-rolling schema plumbing: - AiClient::chatStructured(messages, schema, options) builds a ChatRequest with responseSchema + Capability::StructuredOutput, routes through the normal provider resolution, and returns a typed StructuredResponse (data, raw ChatResponse, isValid/error state). - StructuredOutputParser strips markdown fences and extracts the first balanced JSON object/array from free text; failures yield an invalid StructuredResponse instead of throwing. - Minimal structural validation of the decoded payload against the schema's top-level type (no new dependencies). - OpenAI already maps responseSchema to response_format json_schema (strict); Gemini maps to responseMimeType + responseSchema.
roboshyim
force-pushed
the
feat/structured-output
branch
from
July 21, 2026 16:45
f82e3ee to
5fc4c34
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Exposes a clean, typed, provider-agnostic structured-output API on the
AiClientfacade (P0 roadmap item #4). TheChatRequestvalue object andCapability::StructuredOutputalready existed — this wires them into a usable public API so features (property suggestion, SEO JSON, review summaries) and external plugin devs can request validated JSON without hand-rolling schema plumbing.Public API
Implementation
AiClient::chatStructured(array $messages, array $schema, array $options = []): StructuredResponse— builds aChatRequestwithresponseSchema, routes viaModelResolverto aStructuredOutput-capable provider, parses the result.StructuredResponse(src/Response/) — typed wrapper:->data,->raw,->error,->isValid(),->get(key, default).StructuredOutputParser(src/Client/) — robust extraction: strips ```json markdown fences, pulls the first valid JSON object/array from prose, graceful failure (returns invalid response, never fatals).Tests
tests/Unit/Client/StructuredOutputTest.php(286 lines): schema passthrough toChatRequest, clean JSON, fenced JSON, invalid JSON → invalid response, facade routing. Suite green in container (Shopware 6.7.2.2 / PHP 8.3).Complements the Anthropic provider PR (#3), which implements the tool-use side of structured output.