Skip to main content

Temperature, top-p, structured outputs and determinism

How do temperature and top-p control sampling, and how do you guarantee valid JSON from an LLM?

Official Reference

Model Answer & Explanation

Temperature rescales logits before softmax (0 picks greedy argmax; higher values flatten probabilities). Top-p (nucleus sampling) restricts sampling to the smallest token set whose cumulative probability >= p. For guaranteed JSON, use provider Structured Outputs (constrained decoding against a JSON schema) + Pydantic validation rather than begging in the prompt—and note temperature=0 isn’t 100% deterministic across MoE batches.

Follow-up Interview Question · Why should you change temperature OR top-p rather than tuning both aggressively at once?

Module Context & References

Applied AI & RAG · Popular interview theory Widely asked LLM, retrieval, grounding, agent and evaluation questions
Personal Notes · Markdown

Technologies & Interview Topics Covered

Switch between short-term interview tracks and long-term 80/20 engineering depth to practice JavaScript internals, React rendering and hooks, timed frontend machine coding UI challenges, MeetaPro FG300, Blind 75 & NeetCode 150 DSA patterns, Python & FastAPI APIs, PostgreSQL query optimization & MVCC, Redis caching, Applied AI RAG pipelines & evaluations, and distributed system design.