Stop Optimizing the Prompt. Design the System.
From the publisher’s feed, collected in the ZeroLabs newsroom.
This story is written by me, with a little help from my writing buddy Claude.When an AI tool gives me different results every time, my first instinct is to blame the prompt. Maybe I was not clear enough. Maybe I forgot one rule. So I add a sentence, run it again, and hope.I spent a while doing exactly that, and it did not work.A while ago I built a small AI tool to write product listings for an online shop. Titles, descriptions, keywords, formatting, character limits. I put all of it into one giant prompt and let the model handle everything.The results were different every time I ran it. One run was great. The next one went over the character limit. The third forgot a required field. So I kept adding instructions. The prompt got longer, the token usage went up, and the results were still not consistent.At some point I stopped and asked a different question: why am I asking a language model to do things a ten-line script can do?I was trying to solve a system design problem with prompt engineering.Here is what I changed. It comes down to three principles, and I think they apply to a lot of data science work too.Before and after: one giant prompt versus a small system. Diagram drawn with Claude.1. Separate the creative work from the rule-based workLanguage models are good at things that need language, taste, or judgment. Writing a product description. Picking a tone. Suggesting a title that sounds like a human wrote it.They are not great at being a ruler. “Keep it under 80 characters” is a rule, not a creative task, and I was asking the model to count.If you work with data, you may have seen a version of this. Say you ask an AI to take last week’s raw numbers and give you a summary for your stakeholders. In one prompt you ask it to clean the data, calculate week-over-week change, flag anything unusual, format a table, and write two paragraphs of commentary.Sometimes it works. Sometimes the percentage is slightly off, or a column is quietly dropped, and the commentary sounds confident about a number that was never right. The writing was never the problem. The arithmetic was.The part that needs language is the commentary. Let the model write that. Everything else belongs somewhere else.An example weekly summary pipeline. Diagram drawn with Claude.2. Use code for anything with a fixed ruleIf a rule has a clear right answer, write it as code. Character limits, formatting, required fields, date formats, rounding. A simple script is cheaper than an AI call, it runs in milliseconds, and it gives the same answer every time.In the same weekly summary example, pandas should calculate the metrics. A function should build the table. The model only gets the finished numbers and is asked to explain them in plain English.The model’s job shrinks. That sounds like a downgrade, but it is the opposite. A smaller job means a shorter prompt, fewer tokens, and fewer places for things to go wrong.I used to think a longer prompt meant a smarter system. Now I think a shorter prompt often means I designed the system properly.3. Build a check into the workflowThis is the one I wish I had done from the start. Instead of trusting the AI to follow every instruction, I wrote rules that check the output automatically. If something breaks a rule, it gets flagged before I ever use it.For the listings, that meant checking length, required fields, and formatting after every run.For the weekly summary, I would check things like:Does every number mentioned in the commentary appear in the table?Are there missing values, or a row count that does not match the input?Does the direction of the story (up or down) match the sign of the actual change?None of this is fancy. It is the same instinct as writing a unit test or a data quality check. We would never ship a pipeline without checks, but somehow we trust a paragraph written by a model because it reads well.When a check fails, I do not rewrite the prompt. I look at which part of the system let it through.What changedThe listings became more consistent. Fewer tokens got wasted on retries. And the whole thing became much easier to maintain, because when something breaks I know which piece to open. Before, my only option was to touch the one giant prompt and hope nothing else moved.I should be honest about the limits. This does not make the model perfect. It still writes a bad title sometimes. But now a bad title is a bad title, and not a bad title plus a broken character limit plus a missing field.What I do nowWhen an AI workflow is inconsistent, I ask three questions before I touch the prompt:Who does what. Diagram drawn with Claude.Which part of this needs language or judgment, and which part is just a rule?Can code do the rule-based part?What would catch the output if it were wrong?Most of the time, the answer is not a better prompt. It is a better system.Thank you for reading, and I hope this was useful. If you have an AI workflow that keeps giving you different results, I would love to hear what you changed.Stop Optimizing the Prompt. Design the System. was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.