BUG: --output-schema limited to "gpt-5" as guard is too narrow on model_family.family

Resolved 💬 4 comments Opened Sep 24, 2025 by ben-vargas Closed Sep 24, 2025
💡 Likely answer: A maintainer (pakrym-oai, contributor) responded on this thread — see the highlighted reply below.

What version of Codex is running?

codex-cli 0.41.0

Which model were you using?

gpt-5-codex

What platform is your computer?

Linux 6.8.0-83-generic x86_64 x86_64

What steps can reproduce the bug?

  1. Create a JSON Schema file (e.g. schema.json) describing the expected final answer.
  2. Run codex exec --output-schema schema.json -m gpt-5-codex 'tell me a joke'.
  3. Observe via logging or a mock server that the outbound payload’s text field is null/missing; the response is unstructured text instead of JSON.
  4. Repeat with -m gpt-5; the schema is honored and the model returns JSON.

What is the expected behavior?

Codex models also support the --output-schema flag.

What do you see instead?

  • The new --output-schema feature attaches a JSON Schema via the OpenAI Responses text.format field, but the client only includes that block when model_family.family == "gpt-5" (core/src/client.rs:187).
  • For any Codex-branded model (slugs starting with gpt-5-codex or codex-), find_family_for_model assigns family to the slug itself (core/src/model_family.rs:70-79), so the equality check never passes.
  • As a result, running codex exec --output-schema schema.json -m gpt-5-codex … (or any other Codex slug) sends a request without text.format, the schema is dropped, and the model produces unconstrained free-form output. This is already in the 0.41.0 release.

Additional information

Scope / Impact

  • All Codex-family models using the new --output-schema path ignore the schema, so the flagship use case of constrained Codex output does not work in 0.41.0.
  • Feature works only for plain GPT‑5 slugs, so parity across model presets is broken.

Suspected Fix

  • Broaden the guard in core/src/client.rs to include model families whose slug starts with gpt-5-codex (and likely other Codex prefixes) before calling create_text_param_for_request, rather than relying on an exact "gpt-5" match.

View original on GitHub ↗

4 Comments

ben-vargas · 11 months ago
code@code-hil-1 in projects/unsynced/test2 took 17s
› codex exec --output-schema codex-output-schema.json -m gpt-5-codex --skip-git-repo-check "Respond with a JSON object that satisfies the provided schema and put a short joke in final_answer."
[2025-09-24T18:04:49] OpenAI Codex v0.41.0 (research preview)
--------
workdir: /home/code/projects/unsynced/test2
model: gpt-5-codex
provider: openai
approval: never
sandbox: workspace-write [workdir, /tmp, $TMPDIR] (network access enabled)
reasoning effort: none
reasoning summaries: auto
--------
[2025-09-24T18:04:49] User instructions:
Respond with a JSON object that satisfies the provided schema and put a short joke in final_answer.
2025-09-24T18:04:54.117454Z ERROR codex_core::openai_tools: Failed to convert "firecrawl__firecrawl_extract" MCP tool to OpenAI tool: Error("invalid type: map, expected a boolean", line: 0, column: 0)

[2025-09-24T18:04:56] thinking

**Requesting missing JSON schema**
[2025-09-24T18:04:56] codex

I don’t see a schema in your earlier messages—could you share it so I can format the JSON correctly (punchline pending!)?
ben-vargas · 11 months ago
code@code-hil-1 in projects/unsynced/test2
› codex exec --output-schema codex-output-schema.json -m gpt-5 --skip-git-repo-check "Respond with a JSON object that satisfies the provided schema and put a short joke in final_answer."
[2025-09-24T18:04:11] OpenAI Codex v0.41.0 (research preview)
--------
workdir: /home/code/projects/unsynced/test2
model: gpt-5
provider: openai
approval: never
sandbox: workspace-write [workdir, /tmp, $TMPDIR] (network access enabled)
reasoning effort: none
reasoning summaries: auto
--------
[2025-09-24T18:04:11] User instructions:
Respond with a JSON object that satisfies the provided schema and put a short joke in final_answer.
2025-09-24T18:04:16.465972Z ERROR codex_core::openai_tools: Failed to convert "firecrawl__firecrawl_extract" MCP tool to OpenAI tool: Error("invalid type: map, expected a boolean", line: 0, column: 0)

[2025-09-24T18:04:20] thinking

**Formatting JSON Response**

I need to write a JSON object that meets the codex_output_schema provided. The schema specifies an object with a string property called final_answer. I should ensure there's no special formatting in my output, just plain JSON structure. Since the user asked for a short joke to be included, I'll add one like, "Why did the developer go broke? Because he used up all his cache." Finally, I'll make sure the JSON is valid.
**Preparing JSON Response**

In this environment, I need to keep things concise and straightforward, using the codex_output_schema format. The instructions say that my response should be a JSON object with a property called "final_answer." I’ll include a short joke like, "Why do programmers prefer dark mode? Because light attracts bugs." I must ensure there’s no additional text or trailing spaces—just the JSON structure. It looks like I’m all set to format this correctly!
**Setting JSON Response Format**

In this platform, I can specify the "response format" by using the "final" channel with schema-coded content. It's clear that the output must be in JSON format only. I will set the channel to final and follow the codex_output_schema to ensure everything aligns with the requirements. The content will be a JSON object with the necessary property. I’m ready to move forward and set this up properly!
[2025-09-24T18:04:29] codex
**Preparing JSON Response**

In this environment, I need to keep things concise and straightforward, using the codex_output_schema format. The instructions say that my response should be a JSON object with a property called "final_answer." I’ll include a short joke like, "Why do programmers prefer dark mode? Because light attracts bugs." I must ensure there’s no additional text or trailing spaces—just the JSON structure. It looks like I’m all set to format this correctly!
[2025-09-24T18:04:29] codex
**Setting JSON Response Format**

In this platform, I can specify the "response format" by using the "final" channel with schema-coded content. It's clear that the output must be in JSON format only. I will set the channel to final and follow the codex_output_schema to ensure everything aligns with the requirements. The content will be a JSON object with the necessary property. I’m ready to move forward and set this up properly!
[2025-09-24T18:04:29] codex

{"final_answer":"Why do programmers prefer dark mode? Because light attracts bugs."}
[2025-09-24T18:04:29] tokens used: 8,702
pakrym-oai contributor · 11 months ago

Thank you for the report! Out of curiosity, what are you using codex exec for?

ben-vargas · 11 months ago

Thanks @pakrym-oai for the quick turnaround!

My two most immediate use cases are...

  • Task Master where we need structured JSON for breaking PRDs into detailed tasks.
  • A Vercel AI SDK provider which spawns codex CLI with exec; this will provide more reliable way of implementing generateObject without relying on prompt engineering alone.

So, very valuable and appreciated, this will save me a few headaches by getting reliable structured output from spawned Codex CLI process calls.