Turn Sentry Errors into Reproducible Codex Test Cases

Transforms a production Sentry stack trace and context payload into a self-contained failing unit test designed for Codex repo tasks.

Agent prompt for ChatGPT

You get: Root Cause Summary, test File Path and reproduction Code

Prompt

Prompt
Act as a site reliability engineer and test automation specialist. Convert the production Sentry error dump I paste below into a minimal, reproducible failing test case that OpenAI Codex can run locally.

Rules:
1. Extract the offending function, line numbers, local variables, and error message directly from the frames.
2. Mock all external dependencies, network calls, and database drivers using standard library or common test runners (like pytest or jest); no live connections.
3. Keep the test fixture data scoped strictly to the payload values shown in the Sentry event.
4. Do not speculate on unstated architecture; provide standard stubbing.

Output format:
- Root Cause Summary: 2 sentences identifying the crashing file, method, and payload trigger.
- Test File Path: Suggested location in the repository.
- Reproduction Code: A complete, self-contained test script that fails with the identical exception.
- Assumptions: List any implicit types or environment variables assumed.

Example output

Example for: a Python FastAPI service encountering a TypeError on unhandled null discounts in order totals.

Root Cause Summary

The crash occurs in services/billing.py inside calculate_cart_total when iterating over line items. A coupon payload with discount_percent set to None causes an unsupported operand error during numeric calculation.

Test File Path

tests/unit/test_billing_sentry_repro.py

Reproduction Code
import pytest
from decimal import Decimal
from services.billing import calculate_cart_total

def test_calculate_cart_total_handles_null_discount():
    # Raw payload extracted from Sentry event frame ID 81923
    cart_payload = [
        {"item_id": "sku_99", "price": Decimal("24.50"), "quantity": 2},
        {"item_id": "sku_102", "price": Decimal("10.00"), "quantity": 1}
    ]
    coupon_payload = {
        "code": "SPRING2026",
        "discount_percent": None,
        "applies_to_all": True
    }

    # Reproduction expects the specific TypeError captured in production
    with pytest.raises(TypeError, match="unsupported operand type(s) for *: 'Decimal' and 'NoneType'"):
        calculate_cart_total(items=cart_payload, coupon=coupon_payload)
Assumptions
  • calculate_cart_total expects monetary amounts as Python Decimal objects.
  • No database session is needed because cart calculations operate on pure data structures.
Written by AI from this prompt. Your results will vary.

Tips and common edits

Why this works

  • Forces all network and database layers to be mocked, avoiding flakey dependencies during autonomous Codex runs.
  • Binds reproduction fixtures directly to Sentry frames so the test reproduces the exact bug state without hallucinated logic.
  • Specifies an exact file path and failure assertion, making it easy to hand off directly to Codex for resolution.

Paste your raw Sentry JSON export or stack trace text directly underneath the prompt in Codex or ChatGPT to generate an isolated local test.

Common edits

  • Swap pytest for Jest or Vitest syntax if reproducing frontend or Node.js Sentry traces.
  • Instruct the model to also output an AGENTS.md instruction block so an autonomous agent knows when the task is solved.

Reuse it: Use in a workflowAdapt in the builder

Prompt details

By
Prompts-GPT editors
Published
How prompts are written and checked

Did this prompt work?

More in Codex

Debug Regex and Parsers with GitHub Copilot

Generate an automated audit of regular expressions or parser snippets that flags catastrophic backtracking, isolates edge cases, and produces unit test fixtures.

Agent Orchestration

Create Error Handling Contracts for AI Agents

This prompt transforms raw stack traces into structured error envelopes that provide agents with specific remediation steps and valid parameter constraints for self-correction.

AI Coding AgentsClaude Code

Generate Reproducible Bug Fix Specs for Coding Agents

Get a standalone reproduction test script and a precise technical plan to fix a bug, ensuring your AI agent stays focused and avoids unnecessary file changes.

AI Coding AgentsClaude Code

Evaluate Coding Agent Test Suites for False Positive Traps

Audits agent-generated unit tests to catch tautological assertions, over-mocking, and tests that still pass when core business logic is disabled.