DEVSAIO

Prompts for coding that get better results

How to ask AI for code: give context, constraints and tests, request diffs, and review effectively.

DEVSAIO team · 2 min read
Share on X

Give the context a teammate would need

  • Language and version, framework, key libraries
  • The relevant code (not the whole repo)
  • What you expected vs what happened, with the exact error
  • Constraints: “no new dependencies”, “must work in Node 18”

A bug-fix template

text
Context: Python 3.12, FastAPI, SQLAlchemy 2.
Problem: POST /orders returns 500 when the cart is empty.
Expected: 400 with {"error": "cart is empty"}.

Error:
<paste traceback>

Code:
<paste the route and the function it calls>

Fix the bug with the smallest change. Return a unified diff and a one-sentence explanation. Add a test.

Ask for diffs, not whole files

“Return only the changed lines as a unified diff” is cheaper (fewer output tokens), easier to review, and less likely to silently change unrelated code.

Ask for tests

“Write a test that fails before your fix and passes after.” This forces the model to understand the bug, and gives you proof.

For new features: plan first

text
Plan how to add rate limiting to this API. List files to change and the approach. Don't write code yet.

Correct the plan, then ask for the implementation.

Review like it's a PR

Check edge cases, error handling and security (SQL injection, unvalidated input, secrets). AI code is often plausible-looking; tests catch what reading misses.

For agent tools, see Claude Code workflow tips.

Try it with one API key

Claude, GPT, Gemini, DeepSeek, image and video models through one OpenAI- and Anthropic-compatible endpoint. Prepaid, pay only for what you use.

Keep reading