Evals & Observability·Question 21 of 83Intermediate

How would you build an execution-based eval for a code-generation feature?

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

Execution-based grading is the only honest metric for code: run the model's output and check behaviour. Text similarity to a reference solution is meaningless - infinitely many correct implementations exist.

Full worked answer

Execution-based grading is the only honest metric for code: run the model's output and check behaviour. Text similarity to a reference solution is meaningless - infinitely many correct implementations exist.

Core components:

  1. Task format: each case has a problem statement, a code context (signature, repo snippet), visible examples the model may see, and hidden tests used only for grading. Hidden tests are essential: if graders are visible, models (and your prompt iteration) overfit to them - hardcoding expected outputs passes visible tests and is worthless. HumanEval and SWE-bench both grade on held-out tests.
  2. Sandboxed execution: untrusted generated code gets run in isolation - containers or microVMs with no network, CPU/memory caps, and wall-clock timeouts (infinite loops are a common failure mode, not an edge case). Never exec model output in your CI runner's environment.
  3. Grading logic: pass = all hidden tests green. Partial credit (fraction of tests passed) is useful signal for error analysis but keep the headline metric binary - "80% of tests" often means "wrong." For repo-level tasks, SWE-bench's pattern applies: apply the patch, run the repo's own test suite, require the previously-failing tests to pass (fail-to-pass) and the rest to keep passing (pass-to-pass, catching regressions).
  4. Metrics: pass@1 at your production temperature for the honest product view; pass@k with the unbiased estimator (n ≥ k samples) if your product does best-of-n with verification. Track compile/parse rate separately - syntactically invalid output is a different failure class than logically wrong code.

Operational gotchas that bite in practice: flaky tests (time, randomness, ordering) create eval noise - pin seeds and clocks, quarantine flaky cases; environment drift - pin dependency versions in the image or scores shift when PyPI moves; timeout calibration - too tight and you fail slow-but-correct solutions, blurring correctness with performance.

What a good answer covers

  • Execution-based grading is the only honest metric for code: run the model's output and check behaviour
  • Text similarity to a reference solution is meaningless - infinitely many correct implementations exist
  • Task format: each case has a problem statement, a code context (signature, repo snippet), visible…
  • Sandboxed execution: untrusted generated code gets run in isolation - containers or microVMs with no…
  • Grading logic: pass = all hidden tests green

Key terms: Task format · visible examples · hidden tests · Sandboxed execution · Grading logic · Metrics · flaky tests · environment drift · timeout calibration

Interviewer follow-ups to expect

  1. How do you eval code edits in a large existing repo versus writing functions from scratch?

  2. Your pass rate is 60% - how do you decompose that into actionable failure categories?

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