← All writing

How to Write Better Prompts for LLMs

Four practical ways to give language models clearer instructions, better context, and smaller tasks.

Treat an LLM like a new assistant: explain the task, provide the context, and check the result.

Why prompt writing matters

Large language models can write, summarize, classify, and reason about many kinds of information. They still need clear instructions, though. A vague request often produces a vague answer.

I cannot train a language model from scratch, so my practical goal is simpler: learn how different models behave and give them tasks they can complete reliably.

During a holiday break, I revisited prompt-writing techniques from Professor Hung-yi Lee’s lectures at National Taiwan University. The notes below are the techniques I use most often.

1. Use clear instructions

Phrases such as “think step by step” became popular because they sometimes encouraged a model to spend more effort on a problem. They are not magic switches, and their effect depends on the model and the task.

The useful lesson is to state the work explicitly. Ask the model to identify assumptions, compare options, or check a result. Request the useful output, rather than relying on a special phrase to produce it.

2. Provide the missing context

Treat the model like a new assistant who does not know your project yet. Explain the goal, constraints, intended audience, input format, and definition of a good answer.

Examples can help too. Show one or two representative inputs and outputs when the format is important. If an example is ambiguous, it can confuse the model instead, so keep examples short and representative.

3. Ask for a verification step

A model can produce a plausible answer that still contains a mistake. Add a separate check when accuracy matters.

For example, ask it to list unsupported claims, compare the answer with the supplied source, or run through a checklist before presenting the final result. A check is not a guarantee, but it makes the failure mode easier to see.

4. Break large tasks into smaller ones

Large requests are easier to control when they become a short pipeline. A research task might include searching, extracting facts, organizing notes, drafting, and editing.

Give each step its own prompt and pass only the necessary output to the next step. Add a verification step where the cost of an error is high.

This is also how I tend to design data-science pipelines: make each stage understandable, testable, and replaceable.

A practical prompt pattern

For a medium-sized task, I usually include these parts:

  • Goal: What should the model produce?
  • Context: What does it need to know?
  • Constraints: What must it avoid or follow?
  • Format: What should the final answer look like?
  • Checks: What should it verify before finishing?

The exact wording matters less than making the task concrete. If the output is still inconsistent, reduce the task further or add a small example.

Summary

Clear prompts are useful for everyday work, whether you use an LLM through a chat application or an API. The most reliable habits are to provide context, request a useful format, verify important results, and decompose large tasks.

More advanced patterns, such as Retrieval-Augmented Generation (RAG) and multi-agent systems, build on these basics. I will leave those for another article.

Further reading

These notes were inspired by Professor Hung-yi Lee’s Introduction to Generative AI 2024 lectures: