SproutStackSproutStack home

Understanding LLM Parameters

5 min readBeginner-friendlyFree to read

Read a little, play a little. No scary maths, and no rush.

Share:

Four knobs, two that matter most

Every LLM call carries settings that shape the answer's personality and price. Two dominate daily life; two are supporting cast.

Temperature: the creativity dial

Temperature controls randomness in token picking. At 0, the model always takes the most likely token — same prompt, same answer, ideal for support bots and RAG grounding. At 0.8–1.0, it samples adventurously — stories, brainstorms, varied ideas.

The taste test to run once: ask "give me a tagline for a socks brand" at 0.2, then at 1.0. Same prompt, different universes. Ship factual features at 0.1–0.3; reserve heat for creative ones.

Top-p: the shortlist size

Top-p (nucleus sampling) keeps only the smallest set of tokens covering probability p, then samples within it. top_p=0.9 is the sensible default; lowering it (0.5) makes output safer and duller. Rule of thumb: tune temperature or top-p, not both at once — they interact confusingly.

The supporting cast

  • max_tokens: hard cap on answer length — controls cost and prevents runaway essays, but set too low it truncates mid-sentence.
  • stop sequences: halt strings ("\n\n###") that end generation cleanly — handy for structured parsing.

Temperature in numbers

Suppose the model's next-token options are "great" 70%, "good" 20%, and "fine" 10%. Temperature reshapes those odds before one is picked:

  • Low temperature sharpens them, to something like 95%, 4%, 1%. "Great" wins almost every time.
  • Temperature 1 leaves them as they are.
  • High temperature flattens them, toward something like 50%, 30%, 20%. The unlikely words get a real chance.

Over a long answer these small differences compound, which is why a hot setting can drift into odd phrasing or invented details while a cold one stays predictable.

Sensible starting settings

These are starting points, not rules. Measure on your own task and adjust.

  • Extraction and classification: temperature 0, with structured output, so the same input always gives the same result.
  • Answers grounded in retrieved documents: around 0.2, with a max_tokens cap that fits your interface.
  • General chat assistant: around 0.5 to 0.7, for natural variety without wandering.
  • Brainstorming and creative writing: around 0.9 to 1.0.
  • Code generation: low, around 0 to 0.2, because code needs precision more than surprise.

Other knobs you will meet

  • Frequency and presence penalties discourage the model from repeating the same words or topics. Useful for long creative text, rarely needed elsewhere.
  • Seed, where supported, makes sampling more repeatable for testing, though providers usually do not guarantee identical output.

Not every provider supports every knob, and newer reasoning models may ignore temperature entirely, so check the documentation for the model you call.

Testing a change properly

Because sampling is random, one good or bad answer proves nothing. When you change a setting, run the same set of 10 to 20 prompts before and after, several times each, and compare the results side by side. Change one knob per experiment, and write down what you changed and what you saw. That small discipline turns "it feels better" into evidence.

Remember this

  • Cold (0.2) for facts and RAG with citations; warm (0.8+) for ideas.
  • Cap outputs, use stop strings, and change one knob at a time.

Check your understanding

5 questions · first-try answers earn the most XP

1. You are building a support bot that must quote a refund policy from retrieved documents. Which temperature?
2. You set max_tokens to 30 and the model stops mid-word in the middle of an answer. What happened?
3. Why does the guidance say to change either temperature or top-p, but not both at once?
4. What is a stop sequence used for in a completion request?
5. A team sets temperature 0.8 for every feature including data extraction. What is the likely consequence?

My notes

Saved in this browser. Highlight a line above and save it, or write it in your own words.

Nothing saved yet. Your highlights will live here.

References

Finished reading?

Ticking it here also ticks the chapter in the sidebar, the section count and your streak — it is all one number.

Related chapters

Spotted a mistake or want a topic covered? Report an issue

📬 An occasional email when new lessons land

New lessons and showdowns, no more than a few times a month. No spam, unsubscribe anytime. We store your email only to send the newsletter.