# What belongs in a prompt and what belongs in code?

- **Asked by:** [Aditya Joshi (@aditya_joshi)](https://www.promptabide.com/aditya_joshi)
- **Asked:** 2026-02-09
- **Answers:** 3
- **Upvotes:** 150
- **Views:** 5252

## Question

I keep seeing prompts asked to do arithmetic, sort lists, or enforce a character limit — things a line of code does exactly and a model does approximately. Is there a rule of thumb sharper than 'deterministic things go in code'? The boundary cases are where I keep getting it wrong.

## Answers

### Accepted answer

- **By:** [Vihaan Reddy (@vihaan_reddy)](https://www.promptabide.com/vihaan_reddy)
- **Answered:** 2026-08-22
- **Upvotes:** 73

The rule I use: if you would be angry to find it wrong in the logs, put it in code.

Arithmetic, sorting, truncation, deduplication, date maths, anything with a hard limit — code. Judgement, summarisation, classification with fuzzy boundaries, anything where two reasonable people would disagree — prompt. The boundary cases are usually a task that is secretly two tasks, and splitting them puts each half on the right side of the line.

### Answer

- **By:** [Olivia Tremblay (@olivia_tremblay)](https://www.promptabide.com/olivia_tremblay)
- **Answered:** 2026-08-22
- **Upvotes:** 178

One thing not mentioned yet: log the full prompt and the full response, not a summary, and keep them long enough to debug with. Almost every "the model got worse" report I have chased turned out to be an input change nobody noticed — a template that started rendering an empty section, a retrieval step returning nothing.

You cannot debug what you did not record, and sampled logs always miss the interesting case.

### Answer

- **By:** [Arjun Nair (@arjun_nair)](https://www.promptabide.com/arjun_nair)
- **Answered:** 2026-08-22
- **Upvotes:** 127

Adding to the above — measure the failure rate before you optimise anything. I spent two weeks on prompt tuning for a step that turned out to be failing 0.4% of the time, which was well inside what the downstream process already tolerated.

Instrument first. The expensive problem is rarely the one that feels most annoying.

---

Canonical HTML: https://www.promptabide.com/questions/prompt-vs-code-boundary
Agent guide: https://www.promptabide.com/llms.txt · https://www.promptabide.com/agent-instructions.md
Sitemap: https://www.promptabide.com/sitemap.xml
