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

Open
opened 2026-02-16 18:07:20 -05:00 by yindo · 2 comments
Owner

Originally created by @siggi84 on GitHub (Jan 24, 2026).

Originally assigned to: @thdxr on GitHub.

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.

Originally created by @siggi84 on GitHub (Jan 24, 2026). Originally assigned to: @thdxr on GitHub. ### Feature hasn't been suggested before. - [x] 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: * [https://cookbook.openai.com/examples/codex/build_code_review_with_codex_sdk](https://cookbook.openai.com/examples/codex/build_code_review_with_codex_sdk) That guide demonstrates passing an output schema file and getting guaranteed schema-compliant output, which makes CI integration reliable. **Proposed functionality (illustrative)** ```bash 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.
yindo added the discussion label 2026-02-16 18:07:20 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Jan 24, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #9320: [FEATURE]: support JSON schema as a constrain of opencode run command
  • #5639: [FEATURE]: Support for Structured Outputs in the OpenCode SDK
  • #6879: [FEATURE]: JSON Schema as Source of Truth for API Contracts
  • #6758: Enforcing structured output (c.f. Pydantic) and offload to temporary variables?

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Jan 24, 2026): This issue might be a duplicate of existing issues. Please check: - #9320: [FEATURE]: support JSON schema as a constrain of opencode run command - #5639: [FEATURE]: Support for Structured Outputs in the OpenCode SDK - #6879: [FEATURE]: JSON Schema as Source of Truth for API Contracts - #6758: Enforcing structured output (c.f. Pydantic) and offload to temporary variables? Feel free to ignore if none of these address your specific case.
Author
Owner

@siggi84 commented on GitHub (Jan 24, 2026):

I see now that this might be covered by this issue and pr: https://github.com/anomalyco/opencode/issues/9320

@siggi84 commented on GitHub (Jan 24, 2026): I see now that this might be covered by this issue and pr: https://github.com/anomalyco/opencode/issues/9320
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#7485