Sub topic 3
Asking for Step-by-Step Reasoning
Assume you can write basic prompts, read Python, and work with JSON. This chapter focuses on making multi-step tasks easier to control and test.
Asking for step-by-step reasoning
A reasoning prompt asks the model to handle a task in ordered stages. Instead of asking, “Which plan is best?”, specify a process:
- List the decision criteria.
- Compare each option with those criteria.
- State assumptions.
- Give a recommendation and a short justification.
This structure helps the model cover important parts of the task. For sensitive or complex work, request a concise explanation or intermediate results rather than relying on an unverified answer.
prompt = """
Compare the two database options below.
1. Identify the decision criteria.
2. Score each option from 1 to 5.
3. State any assumptions.
4. Recommend one option in three sentences.
Options:
- SQLite: simple deployment, one application server
- PostgreSQL: multiple services, higher query volume
"""
print(prompt)Splitting complex tasks into chained prompts
Prompt decomposition means splitting one large task into smaller prompts. Each prompt produces an output for the next prompt. For example, one prompt extracts requirements, another finds conflicts, and a final prompt drafts a plan.
Chaining makes failures easier to locate. It also lets code validate each stage before continuing.
Sampling parameters and output variability
Sampling parameters control how a model chooses among likely next tokens. A lower temperature usually produces more consistent wording. A higher temperature can produce more varied ideas. The exact effect depends on the model and platform.
| Goal | Typical choice |
|---|---|
| Classification or extraction | Low temperature |
| Brainstorming | Higher temperature |
Do not use temperature to repair unclear instructions. Improve the prompt first.
Testing and improving prompts systematically
Create a small test set containing normal cases, edge cases, and ambiguous cases. Run each prompt version against the same inputs and measure a clear result, such as exact-match accuracy or valid JSON rate. Change one important variable at a time.
Limits: hallucination and prompt injection
A hallucination is a confident but unsupported statement. Ask the model to mark missing information, provide sources when available, and avoid guessing. Prompt injection is untrusted text that tries to override your instructions. Delimit user data and treat it as data, not commands.
Exercise
Why might a chained prompt be safer than one large prompt?
Show answer
Each stage has a narrower task, so its output can be checked before it becomes input to the next stage.