方寸 Portal

AI Engineer Portal

Your personal operating system for career transition.

Private mode

Exercise

Implement a prompt version registry

Implement a Prompt Version Registry

When you run A/B evals or regression tests across prompt versions, you need a lightweight registry that ties eval results back to exactly the prompt text and metadata that generated them.

What to build

Implement PromptRegistry:

  1. register(name, template, version, metadata=None) -> str — Returns a deterministic prompt_id as "{name}:{version}". Raises ValueError if that prompt_id already exists.

  2. render(prompt_id, variables: dict) -> str — Substitutes {variable} placeholders in the template. Raises KeyError if a required variable is missing.

  3. get(prompt_id) -> dict — Returns {"prompt_id", "name", "version", "template", "metadata"}. Raises KeyError if not found.

  4. list_versions(name) -> list[str] — Returns prompt_ids for all versions of a named prompt, sorted lexicographically.

  5. diff(prompt_id_a, prompt_id_b) -> dict — Returns {"same": bool, "template_a", "template_b"} showing the two templates side by side.

Constraints

  • Standard library only. Templates use Python str.format_map style {variable} placeholders.

Evaluation / medium / Step 28 of 36

Practice stage

Evaluation and review loops

Hint

Separate the scoring logic from the interpretation logic. Your goal is not just a number; it is a useful next action.

Success criteria
  • - Produces a useful signal, not decorative output
  • - Makes regression review easier
  • - Would support a benchmark or observability loop
Review checklist
  • - Would this output help decide what to fix next?
  • - Are important failure modes visible?
  • - Does the score hide any ambiguity I should record?

Practice

Generate a variation

Generate a new exercise variation to deepen understanding or practice a related concept.

Attempt history

Recent submissions

Before you submit, decide what a strong answer should make obvious to the reviewer.

No attempts yet.