Skip to content

[FEATURE]: schema-constrained structured outputs (JSON Schema), similar to Codex #10456

@siggi84

Description

@siggi84

Feature hasn't been suggested before.

  • I have verified this feature I'm about to request hasn't been suggested before.

Describe the enhancement you want to request

OpenCode currently supports JSON-formatted output, but there is no way to enforce conformance to a user-supplied schema (e.g. JSON Schema).

For CI and automation use cases (code review bots, PR comments, policy checks), best-effort JSON is not sufficient. Outputs need to be schema-constrained and deterministic, or the run should fail clearly.

OpenAI Codex provides this via Structured Outputs (JSON Schema), as shown in the Codex CI/code-review guide:

That guide demonstrates passing an output schema file and getting guaranteed schema-compliant output, which makes CI integration reliable.

Proposed functionality (illustrative)

opencode run review \
  --output-schema review.schema.json \
  --output-format json

Where:

  • review.schema.json is a JSON Schema
  • OpenCode guarantees the final output conforms to the schema
  • Failure to conform results in a clear error (not best-effort JSON)
  • This feature might need to be limited to subset of the available models.

Important distinction

This is not about:

  • prompting the model to “output JSON”
  • validating JSON after the fact

The request is for schema enforcement at generation time, similar to Codex’s structured output support.

Why this matters

  • Enables reliable CI/CD and PR review automation
  • Avoids validation + retry loops
  • Complements OpenCode’s LSP support by making outputs machine-actionable

Happy to help test if this is something you’d consider adding.

Metadata

Metadata

Assignees

Labels

discussionUsed for feature requests, proposals, ideas, etc. Open discussion

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions