Sub topic 5
Ask for the right level and format
An explanation can be accurate and still useless if it is pitched wrong. An answer written for an expert leaves you decoding jargon. An answer written for a beginner buries the one detail you needed. This chapter covers how to tell an assistant what depth and what shape of answer you want, so the first reply is close to usable.
This chapter assumes you can read basic Python, have used a chat or editor assistant, and can run small snippets locally. It builds on the earlier chapters about stating your question and structuring a prompt. Here we only tune the output.
Why level and format are separate choices
Two settings shape every explanation.
- Level is how much the assistant assumes you already know and how much detail it includes.
- Format is the shape of the answer: prose, a numbered walkthrough, a table, annotated code, or a diagram.
Keep them separate in your head. A short answer can be expert-level, and a long one can be beginner-level. If you only set one, the assistant guesses the other. Its guess is usually a medium-length essay in a tutorial voice, which fits few real needs.
We use the same running example as before:
from functools import lru_cache
@lru_cache(maxsize=None)
def fib(n):
return n if n < 2 else fib(n - 1) + fib(n - 2)Choose the kind of explanation first
"Explain this code" can mean several different requests. Name which one you want.
| Kind | What you get | Use it when |
|---|---|---|
| Summary | One to three sentences on what the code does | You are scanning a file to decide what to read |
| Walkthrough | Execution in order, with sample values | You need to see how data moves |
| Rationale | Why the code is written this way | You want to know if a pattern is intentional or accidental |
| Line-by-line | A comment for each line or block | The syntax or library calls are new to you |
| Comparison | How it differs from a similar construct | You know a nearby tool and want the delta |
| Risk review | Edge cases, failure modes, assumptions | You plan to change or reuse the code |
A summary and a rationale are different questions. For fib, the summary is "returns the nth Fibonacci number, caching results". The rationale is "without the cache, the recursion recomputes the same subproblems and takes exponential time". If you ask for one, you will not reliably get the other.
Tell the assistant what you already know
The most effective level control is a sentence about your own background. It works better than a label such as "explain like I'm a beginner", because labels are vague and your actual gaps are specific.
Compare these two openings:
Explain this code simply.I'm comfortable with Python functions and recursion. I have not used decorators with arguments, and I have never seen functools. Explain only the decorator line; skip what recursion is.The second does three things. It names what to skip, which saves reading time. It names what is new, which focuses the answer. It sets vocabulary: the assistant can say "memoization" if you know the word, or define it if you say you do not.
Useful phrases for setting level:
- "Assume I know X but not Y."
- "Define any term the first time you use it."
- "Skip basics of X."
- "I know this concept from language Z. Map it to that."
- "Pitch this for someone who maintains this code but did not write it."
The last two are underused. Mapping from a language you know is often the fastest route. For example: "I know JavaScript closures. How does a Python decorator relate to that?"
Choose a format that matches how you will use the answer
Think about what you will do with the explanation in the next ten minutes. Then request the format that serves it.
- Numbered walkthrough when you need to follow execution order.
- Trace table when values change over time. A table of call number, argument, and cache state is easier to check than a paragraph.
- Annotated code when you will keep the explanation next to the source.
- Comparison table when you are choosing between two constructs.
- Diagram when the structure is a tree, a graph, or a sequence of calls between components.
- Short checklist of assumptions when you plan to modify the code.
Here is a prompt that asks for a specific format and level together:
I know Python well but have not used functools. For the code below:
1. Give a two-sentence summary.
2. Give a trace table for fib(5) with columns: call, cache hit or miss, value returned.
3. List what would change if maxsize were 2 instead of None.
Keep each part under 100 words. If a claim depends on the Python version, say so.
<code>
from functools import lru_cache
@lru_cache(maxsize=None)
def fib(n):
return n if n < 2 else fib(n - 1) + fib(n - 2)
</code>Notice the numbered parts. They make the response easy to check against your request, and you can see at a glance if the assistant skipped one.
Picking a level and format: a decision flow
Check a format request against reality
A format request is also a testable claim. If you ask for a trace table of fib(5) and the assistant produces one, you can check it. Run this to see which calls actually execute the function body:
from functools import lru_cache
calls = []
@lru_cache(maxsize=None)
def fib(n):
calls.append(n)
return n if n < 2 else fib(n - 1) + fib(n - 2)
print(fib(5))
print(calls)
print(fib.cache_info())The output is:
5
[5, 4, 3, 2, 1, 0]
CacheInfo(hits=3, misses=6, maxsize=None, currsize=6)The body runs once per distinct argument, six times in total. The three hits are the repeated requests for fib(1), fib(2), and fib(3). If the assistant's trace table shows fib(2) being computed twice, the table is wrong, and you now have the evidence to say so. A structured format makes mistakes visible. Prose can hide them.
Ask for more than one level on purpose
You do not have to settle on one depth. A layered request gives you both a map and the detail:
Explain this in two layers.
Layer 1: one sentence I could say to a teammate.
Layer 2: the mechanism, including what the decorator stores and when it looks it up.This pattern suits unfamiliar code because you usually need a quick orientation first and depth only for the parts that matter. It also helps you notice inconsistency. If layer 1 says "caches results" and layer 2 describes something different, ask about the mismatch.
You can also move levels after the fact:
- "Shorter, keep only what I need to change line 3."
- "Go one level down: what does
lru_cachedo internally on a call?" - "Go one level up: what is the point of this function in a data pipeline?"
Moving up and down is cheaper than writing a perfect first prompt. Treat the first answer as a draft you can steer.
Common mistakes
- Asking for "simple" and getting wrong. Simplified explanations can drop conditions that matter. A claim like "it remembers every answer" is simple, but it is false when
maxsizeis a number, because old entries are evicted. After a simplified answer, ask "what did you leave out that could change my understanding?" - Relying on analogies. A kitchen or library analogy helps for orientation. It can also import details that do not exist in the code. Use an analogy as an entry point, then ask for the literal behavior.
- Over-constraining length. A tight word limit can push the assistant to omit caveats. If you need brevity and caveats, ask for them as a separate line: "one sentence, then a bullet list of caveats".
- Requesting a format the content does not fit. A table of three rows with long cells is worse than a paragraph. Ask for a table when the content has clear columns.
- Forgetting that format does not add certainty. A confident table looks authoritative. It is as reliable as the prose would have been. Verify it the same way.
- Mixing explanation with rewriting. If you ask for an explanation and a cleanup in one prompt, the answer tends to describe the cleaned version, not the original. Ask for the explanation first, and request changes in a separate turn.
Putting it together
A strong level-and-format request has four parts, in any order: your background, the kind of explanation, the format, and any constraint on length or certainty. For this running example:
Background: I know Python and recursion, not functools.
Kind: a rationale, then a walkthrough.
Format: two short paragraphs, then a trace table for fib(5).
Constraint: under 200 words total; mark anything that depends on Python version.You do not need all four every time. For a quick scan, "one sentence summary" is enough. For code you will modify, add the risk review. Match the effort of the prompt to the cost of getting it wrong.
Exercises
Exercise
You are skimming a large module and want to decide whether a function is worth reading closely. Which kind of explanation and which format should you ask for, and why?
Show answer
Ask for a short summary, one to three sentences, in plain prose. A summary answers "what does this do" at the lowest cost and lets you decide whether to ask for a walkthrough or rationale. A trace table or line-by-line comments would give detail you do not need yet.
Exercise
An assistant's trace table says that running fib(5) with lru_cache(maxsize=None) executes the function body 9 times. How can you check this, and what result should you expect?
Show answer
Add calls.append(n) as the first line of the function body, run fib(5), and print len(calls) and fib.cacheinfo(). The body runs 6 times, for n values 5, 4, 3, 2, 1, 0, and cacheinfo() reports hits=3, misses=6. A count of 9 is wrong, so ask the assistant to recheck its trace against this output.
Exercise
Rewrite "Explain this decorator simply" so that it sets level and format. Assume you know Python functions but not decorators, and you want a walkthrough you can keep next to the code.
Show answer
For example: "I know Python functions and recursion but not decorators. Explain the @lru_cache line only. Use annotated code with a comment on each line, then a three-step walkthrough of fib(3). Define any new term the first time you use it." It states your background, the scope, the format, and the vocabulary rule.