Retext
ChatGPTAI AssistantFor Data ScientistsCode Review

ChatGPT Code Review Prompt for Data Scientists

You get a prioritized list of real problems in the code, each tied to a line and paired with a concrete fix, without a pile of style nitpicks. This prompt is tuned for data scientists working in ChatGPT: it carries your role context, and the steps below cover what changes in ChatGPT. Verify that suggested methods fit your data's assumptions, and watch for data leakage between training and test sets in any modeling code.

Installs as a snippet — type ;codereview to paste this prompt anywhere on your Mac.
Prompt Template
Review the code below like a senior engineer on my team would.

## Context
Language and framework: [e.g. TypeScript, Node 20, Express]
What this code does: [one sentence]
What I want you to focus on: [e.g. correctness, readability, edge cases]

## Code
[paste the code or diff]

## Instructions
- Look for bugs first, then edge cases, then readability.
- Point to the specific line or function for every issue.
- For each issue, show the corrected code, not just a description.
- Skip pure formatting comments unless they hide a real problem.
- If something looks wrong but might be intentional, say so and ask.

## Output format
A list grouped by severity:
- Critical: will break or corrupt data
- Should fix: likely bugs, missing edge cases, confusing logic
- Optional: small readability improvements
End with a one-line overall verdict: ready to merge, merge after fixes, or needs rework.

About my work
- Data shape and types: [e.g. 2M rows, columns: user_id, signup_date, plan, churned (bool)]
- Tools and environment: [e.g. Python 3.11, pandas 2, scikit-learn, Jupyter]
- Question the analysis must answer: [e.g. which plan features predict churn in the first 90 days]

Context
- Reference material: [paste it below, or attach the file]

How to use this prompt

  1. 1

    Open ChatGPT

    Start a new chat in ChatGPT and paste the prompt.

  2. 2

    Give it context

    Upload or paste the material the prompt works on below the instructions.

  3. 3

    Review and iterate

    Reply in the same chat to refine, and quote the part you want changed.

  4. 4

    Save what you repeat

    Preferences you want in every chat (tone, audience, format) belong in ChatGPT's custom instructions. For a prompt you reuse with fixed files, a custom GPT or project works too.

Working in ChatGPT

  • •Custom instructions apply to every chat, so keep task-specific rules in the prompt, not there.
  • •If the reply drifts from the format, paste the format line again and ask it to redo only that part.
  • •Start a new chat for unrelated work so earlier messages don't color the answer.

Worked example

What you give it

Language: JavaScript, Node 20
What it does: returns the names for a list of user IDs.
Focus: correctness.

async function getUserNames(ids) {
  const names = [];
  ids.forEach(async (id) => {
    const user = await db.users.find(id);
    names.push(user.name);
  });
  return names;
}

What a good answer looks like (shortened)

Critical
- forEach does not wait for async callbacks, so the function returns an empty array before any lookup finishes. Use Promise.all:

async function getUserNames(ids) {
  const users = await Promise.all(ids.map((id) => db.users.find(id)));
  return users.map((user) => user.name);
}

Should fix
- If an ID does not exist, db.users.find likely returns null and user.name throws. Decide whether to skip missing users (users.filter(Boolean)) or raise a clear error.

Optional
- Promise.all fires every query at once. For very large ID lists, a single query by ID list would be cheaper.

Verdict: needs rework.

Tips for better results

  • •Describe the data with df.dtypes and a few sample rows (with sensitive values removed) instead of words. The AI writes far more accurate code when it sees real column names and types.
  • •Use the focus line in Context to steer the review. "Correctness and edge cases" gets very different feedback than "readability for new hires."
  • •If the reply drifts from the format, paste the format line again and ask it to redo only that part.
  • •Avoid this: Pasting code with no context about what it is supposed to do, so the AI reviews style instead of correctness.

Check before you use it: Verify that suggested methods fit your data's assumptions, and watch for data leakage between training and test sets in any modeling code.

Get the free prompt pack

Our best coding prompts in one Markdown file, delivered by email. The templates here stay free either way — the pack just saves you the copying.

Variations

Pull request review

Replace the Code section with: ## Diff [paste the git diff] and add: Only comment on lines added or changed in this diff.

Team standards

Add this section: ## Our conventions: [paste your style rules or lint config] and flag only violations of these.

Quick pass

Change Output format to: The three most important issues only, one line each, with the fix.

Save it as a Retext snippet

Retext is a free text expander for Mac. Save this prompt once, then type ;codereview in any app (ChatGPT, Claude, your editor, a browser tab) and the full prompt is pasted in.

  1. Click Add to Retext. The prompt installs as a snippet with the trigger ;codereview.
  2. Change the trigger in Retext if you prefer a different one.
  3. Type the trigger wherever you want the prompt, then fill in the brackets.

Frequently asked questions

Can AI choose the right statistical test for my data?

It can suggest options and explain their assumptions, which is a useful check. You still need to confirm the assumptions hold for your data, like independence, sample size and distribution.

Can AI replace human code review?

It is good at catching mechanical mistakes like missed awaits, null checks and off-by-one errors. It does not know your product decisions or team history, so a person should still approve the change.

Should this go in custom instructions?

No. Custom instructions apply to every chat. Keep this prompt for the task and paste it (or expand it with a Retext snippet) when you need it.

How do I reuse this prompt without copying it every time?

Click Add to Retext to save it as a snippet. Then type ;codereview in any Mac app, including your AI tool, and the full prompt is pasted in.

Related Templates

Get the free prompt pack

Our best coding prompts in one Markdown file, delivered by email. The templates here stay free either way — the pack just saves you the copying.