This repository was archived by the owner on Jun 7, 2026. It is now read-only.
feat(gateway): use native --json-schema for structured output - #68
Merged
Conversation
Remove backwards compatibility for pre-1.0.17 Claude CLI output format. The project has always used modern Claude CLI versions, so the legacy `total_tokens_in/out` fields were never needed. - Remove `total_tokens_in/out` from ClaudeCliOutput interface - Update cli.ts to only use `usage.input_tokens/output_tokens` - Update stream.ts to use `usage` object format - Update all test fixtures to use new format
Replace prompt injection approach with Claude CLI's native --json-schema flag for constrained JSON decoding. This provides model-level guarantees of valid JSON output. Changes: - Add jsonSchema option to ClaudeCliOptions, pass as --json-schema flag - Handle structured_output field in CLI response (used by --json-schema) - Add warning log when jsonSchema provided but structured_output missing - Simplify /generate-object route by removing prompt injection - Soften "guarantee" language in comments (external to our code) Type design improvements: - Extract CliUsageInfo interface for shared CLI usage type - Add createUsageInfo() for consistent CLI→API usage conversion - Extract baseRequestSchema to reduce request schema duplication - Add int().nonnegative() refinements to UsageInfo schema - Remove unused outputFormat field from ClaudeCliOptions - Make rawOutput non-nullable in ClaudeCliResult (we throw on failure) - Document unused maxTokens field (CLI doesn't support it) Closes #66
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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
Replaces the prompt injection approach for structured JSON output with Claude CLI's native
--json-schemaflag for constrained decoding. This provides model-level enforcement of valid JSON output.Main Feature (Issue #66)
jsonSchemaoption toClaudeCliOptions, passed as--json-schemaCLI flagstructured_outputfield in CLI response (used when--json-schemais provided)/generate-objectroute by removing prompt injection logicCode Quality Improvements
jsonSchemaprovided butstructured_outputmissing (helps detect CLI version mismatches)total_tokens_in/outfields that were never needed)Type Design Improvements
CliUsageInfointerface for shared CLI usage type (was defined inline in 3 places)createUsageInfo()function for consistent CLI→API usage conversion (eliminates duplication)baseRequestSchemato reduce request schema duplication.int().nonnegative()refinements toUsageInfoschema withtotalTokensconsistency checkoutputFormatfield fromClaudeCliOptions(always hardcoded to "json")rawOutputnon-nullable inClaudeCliResult(we throw on parse failure, never return null)maxTokensfield (CLI doesn't support--max-tokens)Test Coverage
structured_outputcode path (5 new tests in cli.test.ts)/generate-objectwithstructured_outputresponse (2 new tests)Test plan
Closes #66