Skip to content

Commit 03b88f5

Browse files
Fix type and add additional sections on prompt and structured outputs (#2205)
1 parent 1c07a0f commit 03b88f5

File tree

1 file changed

+44
-10
lines changed

1 file changed

+44
-10
lines changed

examples/codex/build_code_review_with_codex_sdk.md

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,56 @@
11
# Build Code Review with the Codex SDK
22

3-
With [Code Review](https://chatgpt.com/codex/settings/code-review) in Codex Cloud, you can connect your team's cloud hosted Github repository to Codex and received automated code reviews on every PR. But what if your code is hosted on-prem, or you don't have Github as an SCM?
3+
With [Code Review](https://chatgpt.com/codex/settings/code-review) in Codex Cloud, you can connect your team's cloud hosted Github repository to Codex and receive automated code reviews on every PR. But what if your code is hosted on-prem, or you don't have Github as an SCM?
44

55
Luckily, we can replicate Codex's cloud hosted review process in our own CI/CD runners. In this guide, we'll build our own Code Review action using the Codex CLI headless mode with both Github actions and Jenkins.
66

77
To build our own Code review, we'll take the following steps:
8-
1. Install the Codex CLI
9-
1. Use the Code Review prompt that ships with the CLI
10-
1. Specify a structured output JSON schema
11-
1. Make API calls to our SCM to create review comments
8+
1. Install the Codex CLI in our CI/CD runner
9+
1. Prompt Codex in headless (exec) mode with the Code Review prompt that ships with the CLI
10+
1. Specify a structured output JSON schema for Codex
11+
1. Parse the JSON result and use it to make API calls to our SCM to create review comments
1212

1313
Once implemented, Codex will be able to leave inline code review comments:
1414
<img src="../../images/codex_code_review.png" alt="Codex Code Review in Github" width="500"/>
1515

16+
## The Code Review Prompt
17+
GPT-5-Codex has received specific training to improve is code review abilities. You can steer GPT-5-Codex to conduct a code review with the following prompt:
18+
19+
```
20+
You are acting as a reviewer for a proposed code change made by another engineer.
21+
Focus on issues that impact correctness, performance, security, maintainability, or developer experience.
22+
Flag only actionable issues introduced by the pull request.
23+
When you flag an issue, provide a short, direct explanation and cite the affected file and line range.
24+
Prioritize severe issues and avoid nit-level comments unless they block understanding of the diff.
25+
After listing findings, produce an overall correctness verdict (\"patch is correct\" or \"patch is incorrect\") with a concise justification and a confidence score between 0 and 1.
26+
Ensure that file citations and line numbers are exactly correct using the tools available; if they are incorrect your comments will be rejected.
27+
```
28+
## Codex Structured Outputs
29+
In order to make comments on code ranges in our pull request, we need to receive Codex's response in a specific format. To do that we can create a file called `codex-output-schema.json` that conforms to OpenAI's [structured outputs](https://platform.openai.com/docs/guides/structured-outputs) format.
30+
31+
To use this file in our workflow YAML, we can call Codex with the `output-schema-file` argument like this:
32+
33+
```yaml
34+
- name: Run Codex structured review
35+
id: run-codex
36+
uses: openai/codex-action@main
37+
with:
38+
openai-api-key: ${{ secrets.OPENAI_API_KEY }}
39+
prompt-file: codex-prompt.md
40+
sandbox: read-only
41+
model: ${{ env.CODEX_MODEL }}
42+
output-schema-file: codex-output-schema.json # <-- Our schema file
43+
output-file: codex-output.json
44+
```
45+
46+
You can also pass a similar argument to `codex exec` for example:
47+
48+
```bash
49+
codex exec "Review my pull request!" --output-schema codex-output-schema.json
50+
```
51+
1652
## Github Actions Example
17-
If you're using Github actions in an on-prem environment, you can tailor this example to your specific workflow. Inline comments highlight the key steps.
53+
Let's put it all together. If you're using Github actions in an on-prem environment, you can tailor this example to your specific workflow. Inline comments highlight the key steps.
1854
```yaml
1955
name: Codex Code Review
2056
@@ -183,9 +219,8 @@ jobs:
183219
printf '%s\n' "Flag only actionable issues introduced by the pull request."
184220
printf '%s\n' "When you flag an issue, provide a short, direct explanation and cite the affected file and line range."
185221
printf '%s\n' "Prioritize severe issues and avoid nit-level comments unless they block understanding of the diff."
186-
printf '%s\n' "After listing findings, produce an overall correctness verdict (\"patch is correct\" or \"patch is incorrect\")"
222+
printf '%s\n' "After listing findings, produce an overall correctness verdict (\"patch is correct\" or \"patch is incorrect\") with a concise justification and a confidence score between 0 and 1."
187223
printf '%s\n' "Ensure that file citations and line numbers are exactly correct using the tools available; if they are incorrect your comments will be rejected."
188-
printf '%s\n' "with a concise justification and a confidence score between 0 and 1."
189224
} > "$PROMPT_PATH"
190225
fi
191226
@@ -453,9 +488,8 @@ pipeline {
453488
printf '%s\n' "Flag only actionable issues introduced by the pull request."
454489
printf '%s\n' "When you flag an issue, provide a short, direct explanation and cite the affected file and line range."
455490
printf '%s\n' "Prioritize severe issues and avoid nit-level comments unless they block understanding of the diff."
456-
printf '%s\n' "After listing findings, produce an overall correctness verdict (\\\"patch is correct\\\" or \\\"patch is incorrect\\\")"
491+
printf '%s\n' "After listing findings, produce an overall correctness verdict (\\\"patch is correct\\\" or \\\"patch is incorrect\\\") with a concise justification and a confidence score between 0 and 1."
457492
printf '%s\n' "Ensure that file citations and line numbers are exactly correct using the tools available; if they are incorrect your comments will be rejected."
458-
printf '%s\n' "with a concise justification and a confidence score between 0 and 1."
459493
} > "$PROMPT_PATH"
460494
fi
461495

0 commit comments

Comments
 (0)