20 Prompts for ChatGPT and GPT-4: From Debugging to System Architecture

Introduction

If you write code five days a week, you have probably already asked ChatGPT to explain a cryptic error or generate a unit test. But most developers use only a fraction of what GPT-4 can do. The difference between a generic answer and a production‑ready solution often comes down to how you phrase the prompt. Over the past year I have collected and battle‑tested roughly two dozen prompts that consistently save time, catch edge cases, and even help design microservice boundaries. This article shares the exact prompts I use daily — from quick debugging to architectural refactoring — with real examples and the reasoning behind each one.

Why prompt engineering matters for code

GPT‑4 is not a mind reader. A vague request like “fix this function” will give you a generic fix that might break your test suite. A precise prompt with context, constraints, and examples returns code that compiles on the first try. The prompts below follow three principles: (1) specify the language and framework, (2) provide the exact error message or expected behaviour, and (3) ask for explanations alongside the code so you can learn instead of copy‑pasting.


1. Debugging a cryptic error

Prompt:

I am getting the following error in Python 3.11 with FastAPI:

Error: "sqlite3.OperationalError: no such column: users.created_at"

Here is the relevant model definition:

[PASTE MODEL]

And the migration file:

[PASTE MIGRATION]

Explain the most likely cause, then provide a corrected migration script. Keep the explanation under 100 words.

Why it works: You give the exact error, the framework, and two files. GPT‑4 can cross‑reference the model with the migration and spot the missing column. The word‑limit forces a concise diagnosis.

Real example: I used this prompt when an Alembic migration skipped a column because of a typo in created_at vs created_at. GPT‑4 found the mismatch in 10 seconds.


2. Refactoring a monolithic function

Prompt:

Refactor the following Python function into smaller, single‑responsibility functions. The function currently handles validation, database writes, and email notifications. Do not change the external API (same parameters and return type). Add type hints and docstrings. Explain why each new function improves maintainability.

[PASTE FUNCTION]

Why it works: You set clear constraints (same API, type hints, docstrings) and ask for justification. This turns the output into a teaching moment.


3. Generating unit tests with edge cases

Prompt:

Write pytest tests for the function below. Include:
- 3 normal cases
- 2 edge cases (empty input, None values)
- 1 error case (invalid type)

Use pytest fixtures for setup. Do not use mocks unless necessary. Explain why each test case matters.

[PASTE FUNCTION]

Why it works: Specifying the number and type of test cases prevents GPT‑4 from generating only happy‑path tests.


4. Explaining a complex codebase

Prompt:

I am new to this Django project. Explain the data flow for the "order checkout" feature. List the models, views, and serializers involved. Draw a sequence diagram in text format (using arrows and steps). Keep the explanation under 300 words.

Why it works: The request for a text diagram forces GPT‑4 to structure the answer logically. The word limit keeps it readable.


5. Designing a microservice boundary

Prompt:

I have a monolithic e‑commerce app with user management, product catalogue, order processing, and payment. Suggest a microservice decomposition. For each service, list:
- its bounded context
- main entities
- API endpoints (REST or gRPC)
- data store type (SQL, NoSQL, cache)
- communication pattern (sync vs async)

Assume 10,000 concurrent users. Justify your choices.

Why it works: The prompt includes a concrete load assumption and asks for justification, which prevents generic advice.


6. Code review simulation

Prompt:

Act as a senior developer reviewing this pull request. List the top 3 issues you find, ordered by severity. For each issue, explain the risk and suggest a fix. If there are no major issues, say "Looks good" and suggest one minor improvement.

[PASTE CODE]

7. Converting between languages

Prompt:

Convert the following JavaScript function to Go. Use idiomatic Go patterns (error handling, structs, no classes). Preserve the same logic but adapt to Go conventions. Add comments explaining key differences.

[PASTE FUNCTION]

8. Writing a database query (complex joins)

Prompt:

Write a PostgreSQL query that returns:
- customer name
- total orders in the last 30 days
- total revenue from those orders
- average order value

Tables: customers (id, name), orders (id, customer_id, total, created_at).
Optimise for performance. Use indexes where appropriate. Explain the query plan.

9. Generating a Dockerfile

Prompt:

Create a multi‑stage Dockerfile for a Python 3.11 FastAPI app that uses Poetry for dependencies. The final image should be based on python:3.11‑slim. Include a healthcheck. Explain each stage.

10. Explaining a Git conflict

Prompt:

I have a merge conflict in a Python file. Here is the conflict marker:

[PASTE CONFLICT]

The left side is my branch (feature/payment), the right side is main. Explain what each side changed and suggest a resolution that keeps both features if possible.

11. Writing a bash script for automation

Prompt:

Write a bash script that:
- takes a directory as argument
- finds all Python files modified in the last 7 days
- runs `black` on them
- if black changes a file, commit it with message "style: format [filename]"
- prints a summary of formatted files

Make it safe to run (check for uncommitted changes first).

12. Creating an API client

Prompt:

Write a Python class that wraps the Stripe API for creating and retrieving payments. Use the official stripe library. Include error handling for network timeouts and invalid API keys. Add type hints and a minimal usage example.

ASI Biont supports integration with Stripe through its API — learn more at asibiont.com/courses.


13. Optimising a slow query

Prompt:

This SQL query takes 12 seconds on a table with 2 million rows. Analyse the execution plan (I will paste it below) and suggest three optimisations. For each, explain the expected improvement and any trade‑offs.

[PASTE EXPLAIN ANALYZE OUTPUT]

14. Writing a CI/CD pipeline snippet

Prompt:

Write a GitHub Actions workflow that:
- runs on push to main
- sets up Python 3.11
- installs dependencies with Poetry
- runs tests with pytest
- runs linter (flake8)
- if tests pass, builds a Docker image and pushes to Docker Hub

Use caching for dependencies.

15. Generating a regular expression

Prompt:

Write a regex that matches:
- US phone numbers in formats (123) 456‑7890, 123‑456‑7890, and 1234567890
- must not match strings with letters
- explain each part of the pattern

Test it against these examples:
- (800) 555‑0199 -> match
- 800‑555‑0199 -> match
- 8005550199 -> match
- 12345 -> no match

16. Explaining a security vulnerability

Prompt:

I found this code in our codebase. Identify any security vulnerabilities (SQL injection, XSS, CSRF, etc.). For each vulnerability, explain how an attacker could exploit it and provide a fix.

[PASTE CODE]

17. Writing a data migration script

Prompt:

Write a Python script that reads from a CSV file with columns: user_id, email, signup_date. It should:
- validate email format
- skip duplicate user_ids (log them)
- insert into a PostgreSQL table `users`
- use batch inserts (100 rows at a time)
- handle rollback on error

Add progress logging.

18. Summarising a technical article

Prompt:

Summarise the following blog post about microservices observability in 5 bullet points. Each bullet should be a concrete takeaway, not a generic statement. Assume I am a backend developer with 3 years of experience.

[PASTE ARTICLE TEXT]

19. Generating a Makefile for common tasks

Prompt:

Create a Makefile for a Python project with these targets:
- `install` — install dependencies with Poetry
- `test` — run pytest with coverage
- `lint` — run flake8 and black check
- `format` — run black
- `docker‑build` — build Docker image
- `clean` — remove __pycache__ and .pyc files

Use variables for the image name and Python version.

20. Debugging a race condition

Prompt:

I have a multithreaded Python script that sometimes produces inconsistent results. Here is the code:

[PASTE CODE]

I suspect a race condition on the shared `counter` variable. Identify the exact lines where the race condition occurs and suggest a fix using threading.Lock or queue. Explain why the fix works.

Conclusion

The prompts above are not magic — they are structured conversations. The key is context: every prompt includes the language, framework, error, expected behaviour, or constraints. Over time, I have learned that GPT‑4 gives its best output when you treat it like a junior developer who needs clear instructions and examples. Copy these prompts, adapt them to your stack, and you will save hours each week. The real power is not in asking for code — it is in asking for explanations alongside the code, so you become a better developer with every answer.

← All posts

Comments