﻿# Use structured Codex exec output as an application artifact

Use Codex exec output schemas to return predictable review fields while keeping artifact identity and validation evidence separate from JSON parsing success.

Author: Retrivium editorial team
Updated: 2026-11-03
Canonical URL: https://retrivium.ai/journal/learn-codex-exec-schema/
Language: en

A noninteractive Codex task often needs to return data to another program. The documented output-schema option constrains the final response to a JSON shape. That gives the next stage stable fields without making the field values automatically sufficient for a deployment or review decision.

## Choose fields that answer the next stage’s questions

An illustrative review schema can identify affected paths, describe validation and retain unresolved questions. Each field has a distinct consumer. Avoid using a single success string to carry all of that information, because downstream code would need to recover structure from prose before it could decide what to show.

```json
{
  "type": "object",
  "properties": {
    "changed_paths": { "type": "array", "items": { "type": "string" } },
    "validation": { "type": "string" },
    "remaining_questions": { "type": "array", "items": { "type": "string" } }
  },
  "required": ["changed_paths", "validation", "remaining_questions"],
  "additionalProperties": false
}
```

## Request the final artifact explicitly

The noninteractive documentation describes --output-schema and the output-last-message option. The example below requests the schema and saves the final response to a named file. It assumes a prepared repository and an existing schema file; it does not perform those setup steps or execute a real review in this article.

```bash
codex exec "Inspect the change and return a review summary"   --output-schema ./review-schema.json   -o ./review-result.json
```

## Give an empty collection a defined meaning

An empty changed_paths array can mean that no relevant edits were found. It should not silently mean that the process failed to inspect the repository. Define what evidence must accompany that state. Likewise, unresolved questions should remain an explicit collection rather than disappear into an optional paragraph that the consumer never reads.

## Keep artifact checks outside the text field

The consumer can verify that returned paths belong to the intended workspace and that the referenced files exist. This is application logic around the result, not an additional property guaranteed by a JSON schema. A small field map makes the responsibility concrete.

| Field | Intended meaning | Downstream use |
| --- | --- | --- |
| changed_paths | Files included in the review | Locate the actual artifacts before showing a diff. |
| validation | What was checked and what was observed | Present evidence without inferring execution from an empty field. |
| remaining_questions | Unresolved task dependencies | Keep uncertainty visible instead of converting it to approval. |

## Test the consumer with contrasting results

A proposed fixture can include a complete review, a valid empty result and a response listing unresolved inputs. The consumer should display each state honestly. This tests the handoff between Codex and the application. It does not measure model accuracy, and it should not fabricate test execution merely because the final JSON parsed successfully.

## Documentation and further study

- [Non-interactive mode](https://learn.chatgpt.com/docs/non-interactive-mode).

- [Codex as a platform: build on the open agent harness](https://developers.openai.com/blog/codex-as-a-platform).

- [Codex App Server](https://learn.chatgpt.com/docs/app-server).

Related engineering guides: [Reproducible inference stacks: preserving a GPU pilot’s result](/journal/software-stack-reproducibility/); [Choose a local AI stack: desktop chat, shared UI or coding agent](/journal/local-ai-app-stack-selection/).
