Evals & Observability·Question 6 of 83Basic

Define pass@k. Why is the naive way of computing it problematic, and what's the fix?

Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.

Model answer: the part to lead with

pass@k is the probability that at least one of k independent samples from the model solves the problem - the standard metric for code generation (HumanEval popularised it), where you can cheaply verify each sample by running tests.

Full worked answer

pass@k is the probability that at least one of k independent samples from the model solves the problem - the standard metric for code generation (HumanEval popularised it), where you can cheaply verify each sample by running tests.

The naive computation - generate exactly k samples, score 1 if any passed, average over problems - is an unbiased-in-expectation but high-variance estimator: for each problem you get a single Bernoulli observation, so results swing run to run, especially for small eval sets and mid-range success probabilities.

The fix, from the Codex paper: generate n ≥ k samples per problem (say n = 200 for k ≤ 100), count c correct, and compute the probability that a random size-k subset contains at least one correct sample:

pass@k = 1 − C(n−c, k) / C(n, k)

This averages over all C(n, k) subsets analytically instead of sampling one, slashing variance. Computing binomials directly overflows, so use the numerically stable product form:

import numpy as np

def pass_at_k(n: int, c: int, k: int) -> float:
    if n - c < k:
        return 1.0
    return 1.0 - np.prod(1.0 - k / np.arange(n - c + 1, n + 1))

Going further: follow-up territory

Two things a strong candidate adds. First, sampling temperature interacts with k: higher temperature hurts pass@1 but helps pass@100 (more diversity), so report the temperature and tune it per k. Second, pass@k measures best-case capability - fine when you can verify and pick the winner (hidden tests, a compiler), misleading when you can't. For reliability-critical agent settings the complementary metric is pass^k - the probability that all k independent trials succeed (popularised by τ-bench) - which punishes the inconsistency that pass@k hides. A model with 80% per-trial success has pass^8 ≈ 17%: great demo, unreliable product.

What a good answer covers

  • pass@k is the probability that at least one of k independent samples from the model solves the problem -…
  • The naive computation - generate exactly k samples, score 1 if any passed, average over problems - is an…
  • This averages over all C(n, k) subsets analytically instead of sampling one, slashing variance

Key terms: at least one · high-variance · n ≥ k

Interviewer follow-ups to expect

  1. When is optimising pass@10 legitimate for a product?

  2. How does pass@k relate to best-of-n sampling with a verifier at inference time?

Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep