Skip to content

[Enhancement] Prompt template registry with versioning and A/B experimentation #60

Description

@zeemscript

Summary

The single most important lever on answer quality — the system prompt — is a hardcoded string literal in the middle of main.py, with no version, no history, and no way to change it without a code deploy or to test whether a change actually helped. Improving the assistant means iterating on this prompt constantly, and right now every iteration is a blind, unmeasured edit. This issue turns the prompt into managed infrastructure: a versioned template registry with named, parameterized templates, and an A/B experimentation harness that can run two prompt versions against real traffic and measure which produces better answers. This is the substrate that makes all the other answer-quality work measurable.

Current state

What to build

  1. A prompt registry — extract prompts out of main.py into a managed store (versioned files or a small module, e.g. prompts/ with a loader) where each template has a stable name, a semantic version, a changelog entry, and typed variables (madhhab, language, knowledge_level, intent, retrieved_context). Compose with [Bug] Islamic system prompt is skipped for plain requests and easily overridden by prompt injection #5's system_instruction change rather than reverting it. Rendering is deterministic and unit-tested.
  2. Template parameterization — a small, safe rendering layer (no arbitrary code execution, injection-safe) so other issues fill variables instead of string-concatenating into the handler. Publish the variable contract so [Enhancement] First-class Arabic and multilingual support #14/[Enhancement] Madhhab-aware fiqh answers: present the positions of the major schools instead of one flattened ruling #39/[Enhancement] Per-user long-term memory and conversation summarization for personalized answers #41 target it.
  3. An A/B experiment harness — assign each request (by chat_id/user_id hash, so a session is sticky) to a prompt variant per an experiment config, record the assignment with the response, and expose the variant in optional response metadata for offline analysis. Support a control + one-or-more variants and a kill switch.
  4. Measurement hook — join experiment assignments to a quality signal (feedback ratings from [Enhancement] Answer feedback capture and a quality-improvement loop feeding the evaluation dataset #43, eval-harness scores from [Enhancement] Evaluation harness for Islamic answer quality #16, or confidence from #ai-19) so a variant's win/loss is computable. Do not build a new metrics store — emit to the ones those issues define.
  5. Config-driven — experiment definitions and the active prompt version live in configuration (coordinate with the pydantic-settings work [Enhancement] Centralize configuration with pydantic-settings (model, generation params, CORS origins) #10) so changing the live prompt or starting an experiment needs no code change.
  6. Tests — offline tests for deterministic rendering, variable substitution, sticky variant assignment (same session → same variant), the kill switch, and that metadata records the variant. No live API calls in CI.

Acceptance criteria

Pointers

Difficulty

Medium — the template registry and sticky variant assignment are standard, well-scoped engineering, but doing it right means designing a clean variable contract that a half-dozen other issues will build on, composing carefully with the in-flight system_instruction change, and wiring measurement to existing signals rather than sprawling a new metrics system.


🏆 GrantFox OSS — Official Campaign | FWC26. Apply for this issue through the GrantFox campaign page. The maintainer assigns one contributor before work starts; unassigned PRs may not be reviewed. PRs target the dev branch. Quality bar: CI must stay green.

💬 Questions or need help? Reach the maintainers and other contributors on the DeenBridge Telegram: https://t.me/+nst9lXNj1wc4ZDE0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions