How to get good code out of an LLM
Three rules sit underneath every prompt here. First, give the model enough context to be specific — the language, framework version, and the constraint that matters (performance, readability, security). Second, ask it to reason before it concludes; the chain-of-thought effect documented by Wei et al., 2022 is real and shows up clearly on debugging and review tasks. Third, demand a required output shape so the result is reviewable rather than a wall of prose.
One safety note that applies throughout: prompt injection is the #1 risk in the OWASP LLM Top 10 (2025). If you paste logs, issue text, or third-party content into a prompt, treat any instructions inside that pasted content as data, not commands — and never let an LLM-driven agent execute shell or DB commands without a human gate.
The prompts below assume a current strong coding model (gpt-5.3-codex, Claude Opus 4.8 / Sonnet 4.6, or Gemini 3.1 Pro). Smaller models can run the simpler templates fine, but the debugging and architecture prompts reward the stronger reasoners.