Prompt Design for LLMs: Matching Solution Complexity to the Problem
This article explains why large language models often return over-engineered solutions to simple problems, and why this happens. It covers four elements of a useful task instruction (goal and scope, a complexity limit, simple-first answers, and output format with stop conditions), with a before-and-after example, a reusable prompt template, a dependency check, and a review checklist for teams.
1. The Problem: Simple Requests Turned Into Complex Engineering
Many developers using large language models have run into a familiar situation. They want to solve a small problem, such as counting the elements in a list that meet a condition, but the model returns a complete plan with a task queue, a cache layer, a configuration center, and monitoring with alerts. The code runs and the architecture diagram is thorough, but the answer is out of proportion to the problem.
This pattern has three typical traits. First, the solution layer exceeds the requirement layer: a single function call gets split across several services. Second, the answer introduces dependencies that are not needed, such as a full parsing framework for one string replacement. Third, the answer emphasizes technical depth and says little about cost, maintenance effort, or alternatives.
This output is not random. A model generates text according to a probability distribution. In training data, formal engineering documents, architecture discussions, and production code are usually longer and more structured. When the prompt sets no limits, the model tends to produce content that looks professional.
2. Why Stronger Models Over-Engineer More Easily
Intuitively, a more capable model should be better at making trade-offs. In practice, the situation is more complicated.
A more capable model can think of more feasible solutions. Given one problem, it may consider a dozen implementation paths at once. If the prompt does not set priorities, it often picks the option with the broadest coverage and the most complete appearance.
Second, models have a strong preference for completeness. If an answer omits exception handling, logging, or extension points, the model tends to add them, and the cost of those additions is usually not weighed.
Third, the model has no real sense of cost. It does not take on the risk of a failed deployment, and it does not get woken up by an alert in the middle of the night. The responsibility for judging whether a solution is worth its cost falls on the user, so the instruction must state the cost dimension explicitly.
Finally, human requests often carry implicit constraints, such as “do not add new dependencies” or “change only the current file.” Developers assume these conditions by default, but the model cannot infer them unless they are stated.
3. Why Simplicity First Matters in Engineering
In software engineering, simple solutions usually have the following advantages.
First, they are easier to understand. Shorter code with a more direct structure lets the next person read it faster.
Second, they are easier to verify. Fewer dependencies mean fewer paths to test, and faults are easier to locate.
Third, they are easier to reverse. A simple solution is easy to replace when requirements change. Once a complex solution is live, rolling it back often means coordinating changes across several modules.
Fourth, their cost is easier to control. Each added component adds operational work, including deployment, monitoring, permissions, and troubleshooting.
For these reasons, solving a simple problem with a complex method goes against engineering experience. This does not mean complex solutions have no value. When the scale of the requirement, the availability target, or the data volume truly reaches a certain threshold, a complex solution is the right choice. The problem is that the model needs to know where that threshold is, and the prompt must tell it.
4. Four Elements of an Effective Constraint Instruction
A useful task instruction usually includes the following four elements.
1. Define the goal and scope
The goal states the specific problem to solve. The scope states the boundaries of what may be changed or output. For example, “add one parameter check inside the existing function” is easier to act on than “optimize input handling,” because the first limits both the location and the action.
2. Set a complexity ceiling
The complexity ceiling is the most important constraint. It can be expressed as measurable conditions, for example:
- Prefer the language standard library and do not add new third-party dependencies;
- Change no more than two files;
- Do not add network requests, database tables, or background processes;
- Keep each function under forty lines.
The ceiling does not need to be exact, but it must be checkable. A vague instruction such as “keep it simple” has little effect on the model.
3. Ask for the simple solution first, then its cost
This element noticeably improves the structure of the output. The instruction can ask the model to answer in this order: first, the simplest solution that meets the requirement; second, the extra benefits and extra costs of more complex options; and last, the decision is left to the user. Complex options stay visible, but they are not adopted by default.
4. Specify the output format and stop conditions
A clear output format, such as “output only the modified function with one sentence of explanation,” prevents long architecture discussions. Stop conditions matter too. For example, “if the requirement is underspecified, ask at most three questions before giving any implementation” keeps the model from guessing.
5. A Before-and-After Comparison
A practical scenario shows the difference.
Instruction before revision:
Help me implement a feature that counts the number of error-level entries in a log file.
This instruction does not specify a language, input size, dependencies, or output format. The model will likely produce a small tool with command-line argument parsing, multithreaded reading, result persistence, and report export.
Instruction after revision:
Goal: Count the lines in a log file that contain the word ERROR.
Scope: Output only one function that takes a file path and returns an integer.
Constraints: Use only the standard library. The file may be large, so read it line by line and do not load it all into memory. Do not write any files and do not introduce additional services.
Output: First give the simplest implementation. Then, in two or three sentences, explain what changes would be needed to count by time range or by severity level, and what those changes would cost.
The answer to the second instruction usually contains about a dozen lines of code, followed by a short note on extensions. The requirement has not changed, but the boundaries have, and the model’s output narrows accordingly.
6. Encoding Constraints in Code
Inside a team, these elements can be wrapped in a template so none is forgotten each time. The following function builds a task instruction with a consistent structure:
def build_task_prompt(goal, scope, constraints, output_format):lines = [f"Task goal: {goal}",f"Scope: {scope}","Constraints:",]lines += [f"- {c}" for c in constraints]lines.append(f"Output format: {output_format}")lines.append("If there are several options, first give the simplest solution that meets the requirement, ""then explain the extra benefits and costs of the more complex options. ""The user decides whether to adopt them.")return "\n".join(lines)prompt = build_task_prompt(goal="Count the lines in a log file that contain ERROR",scope="Output only one function that takes a file path and returns an integer",constraints=["Use only the standard library","Read line by line; do not load the entire file at once","Do not write to files and do not introduce additional services",],output_format="Code plus two or three sentences of extension notes",)print(prompt)
After the model responds, you can run an automatic check to confirm that the answer did not introduce unapproved dependencies. The following function uses regular expressions to extract import statements from the response and compares them with a list of approved dependencies. It is a rough check and works best as an aid to review:
import reSTANDARD_OK = {"re", "os", "sys", "json", "pathlib", "collections", "itertools"}def find_unapproved_imports(response_text, approved_deps=frozenset()):names = set(re.findall(r"^\s*import\s+([\w\.]+)", response_text, re.M))names |= set(re.findall(r"^\s*from\s+([\w\.]+)\s+import", response_text, re.M))allowed = STANDARD_OK | set(approved_deps)top_level = {n.split(".")[0] for n in names}return sorted(top_level - allowed)sample = """import reimport requestsdef count_errors(path):..."""print(find_unapproved_imports(sample)) # Output: ['requests']
This check is simple. It cannot detect dynamic imports or indirect dependencies, but it catches the most common case, where the model casually adds a third-party library.
7. A Review Checklist
Before using model output in a real project, check the following:
- Is the number of components proportionate to the size of the requirement?
- Does the output introduce new dependencies, services, or storage?
- Does the change go beyond the files or functions the instruction specified?
- Do verifiable test cases cover the core path?
- Has the extra cost of a complex option been stated?
- If something goes wrong, is it easy to roll back?
You do not need to run through this list in full every time. For tasks involving releases, data writes, or permission changes, confirm each item.
8. Iterating on Instructions
The first version of a set of constraints is rarely complete. A better approach is to record each deviation in the output and add the matching restriction to the template. For example, if the model keeps generating configuration files, add “Do not generate configuration files unless explicitly requested.” After several rounds, a team builds up an instruction library tailored to its own stack and business scenarios, which tends to work better than any general-purpose prompt.
Be aware that over-constraining also causes problems. If the limits are too strict, the model may return a simplified solution that does not run, or it may skip error handling that is actually needed. Constraints should serve the requirement itself, balancing “enough” against “complete.”
9. Scope of Applicability
The principles in this article apply to most everyday development work, including writing functions, scripts, small refactors, and data processing. For high-concurrency system design, security-sensitive modules, and scenarios with compliance requirements, a complex design may be necessary. In those cases, the instruction should state the scale, availability, and security requirements, so the model works toward those targets instead of defaulting to complexity.
In short, the instruction lets the user define what level of solution is appropriate, and the model works within that range.
