Skip to content

DSPy Prompt Optimization Subsystem

Overview

Rather than manually tweaking prompt strings (prompt crafting), the platform integrates DSPy (src/optimization/) to optimize agent prompts through declarative signatures and metric-driven teleprompters.

Optimization Architecture

[ Declarative DSPy Signature ]
Defines inputs, outputs, and reasoning boundaries
|
v
[ Synthetic & Golden Training Sets ]
Curated Life Sciences test cases
|
v
[ DSPy Teleprompter (BootstrapFewShotWithRandomSearch) ]
Iteratively compiles optimal few-shot demonstrations and instruction adjustments
|
v
[ Composite Regulatory Metric ]
Scores candidates on FMEA math, 5-Whys depth, and tone adherence
|
v
[ Prompt Registry & Versioning ]
Approved prompts committed to database with semantic version tags

Declarative Signatures

Optimization signatures are defined declaratively in src/optimization/signatures.py:

  • DeviationAnalysisSignature: Maps deviation description, affected equipment, and product impact to root cause deduction and CAPA actions.
  • CsaRiskScoringSignature: Maps software module details and intended use to GAMP category and CSA rigor recommendation.
  • RequirementsMappingSignature: Maps URS statements to functional and technical specifications.

Prompt Registry & Version Management

Optimized prompt templates are stored in PostgreSQL table prompt_registry:

  • prompt_id: Unique identifier (e.g. deviation_rca_v2).
  • signature_name: Name of the corresponding DSPy signature.
  • version: Semantic version string.
  • benchmark_score: Evaluation score achieved during validation.
  • is_active: Boolean flag designating the currently active production prompt.

This architecture ensures that prompts can be updated and promoted without code redeployment, while maintaining a complete audit trail of prompt evolution.