feat(ai): replace JSON parsing with structured output via tool_use - #66
Merged
Conversation
Replace fragile 3-tier JSON parsing (JSON.parse → jsonrepair → brace-matching) across report generator, plan tuner, and plan parser with Claude's tool_use structured output, guaranteeing schema-valid responses. - Add StructuredOutputConfig interface + completeStructured() to AIProvider - ClaudeProvider: tool_choice forced tool call extracts schema-constrained JSON - GeminiProvider: responseMimeType + responseSchema for equivalent behavior - Add completeStructuredWithRetry() to retry-utils - Report generator: remove extractFirstJson, parseAIResponse, isValidScorecard - Plan tuner: remove parseTunerResponse, extractFirstJson, retry-on-parse loop - Plan parser: LLM structured output with regex fallback when AI unavailable - Remove jsonrepair dependency - Add rawText size cap to PUT /api/workout-plans/:id (security review fix) - Add flagSuspiciousInput to plan parser LLM path (prompt injection defense) - Update docs/architecture.md: file tree, API endpoints, data model tables - Add Phase 8 documentation checklist to ADE workflow in CLAUDE.md Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
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.
Summary
completeStructured<T>()to AIProvider — uses Claude'stool_choice(forced tool call) and Gemini'sresponseSchemato guarantee schema-valid JSON responsesjsonrepairdependency — ~250 lines of parsing code eliminated, retry-on-parse-failure loop removedFiles changed (17)
ai.tsStructuredOutputConfiginterface, +completeStructured()on AIProviderclaude-provider.ts,gemini-provider.tscompleteStructured()retry-utils.tscompleteStructuredWithRetry()report-generator.tstuner.ts,tuner-prompt-builder.tsplan-parser.tsworkout-plans.tspackage.json,package-lock.jsonjsonrepairarchitecture.md,CLAUDE.md, plan statuscomplete→completeStructuredTest plan
npm run lint— 0 errorsnpm run format:check— cleantscbuild clean (shared + backend)🤖 Generated with Claude Code