方寸 Portal

AI Engineer Portal

Your personal operating system for career transition.

Private mode

Exercise

Implement a prompt version registry with promotion logic

Implement a prompt version registry with promotion logic

Prompt changes that degrade quality need to be detectable and rollback-able. This exercise builds the minimal data structure for version-controlled prompts.

What you are building

Implement a PromptRegistry class that manages versioned prompt templates per feature:

Methods to implement:

  • create(feature: str, template: str, variables: list[str]) -> int — Create a new draft version. Returns the version number.
  • promote(feature: str, version: int) -> None — Promote a draft version to production. Retires the previous production version.
  • get_active(feature: str) -> dict | None — Return the current production version dict (with feature, version, template, variables, status).
  • rollback(feature: str) -> bool — Restore the most recently retired version to production. Returns True if successful, False if no retired version exists.
  • list_versions(feature: str) -> list[dict] — Return all versions for a feature, sorted by version number ascending.

Requirements

  • Versions auto-increment per feature starting at 1
  • Only one version per feature can be in "production" status at a time
  • Promoting a version sets its status to "production" and the previous production version to "retired"
  • Status values: "draft", "production", "retired"
  • Store everything in-memory (a dict is fine)

Prompt Formatting / medium / Step 4 of 5

Practice stage

Prompt boundary discipline

Hint

Treat prompt construction like request composition: trusted instructions, untrusted user input, and context blocks should stay separate.

Success criteria
  • - Separates system, user, and context cleanly
  • - Avoids string chaos and hidden assumptions
  • - Would scale to a real LLM feature
Review checklist
  • - Did I preserve trusted versus untrusted boundaries?
  • - Would this format survive longer prompts and more context?
  • - Can another engineer review the structure quickly?

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.