Align Prompt Library¶
align_prompt_library — mvp.align_prompt_library
Cluster: Safety & Alignment | Type: component | MCP Tools: 27
Overview¶
Versioned prompt store with template rendering, full-text search, tag and category filtering, and variable validation. The direct block keeps prompts in memory unless db_path is provided; the MCP block uses SQLite persistence by default. Each store call auto-increments the version for a named prompt and populates id and timestamps; render substitutes {{variable}} placeholders from supplied values and fails when required values are missing; validate extracts placeholder names without storing. The extended AlignmentBlock sub-component adds alignment specification storage alongside prompt management and now persists specs/goal trees to SQLite when db_path is supplied. The 27-operation MCP sub-package wraps deterministic CRUD (prompts, alignment specs, goal trees, version history/rollback), adds pl_capabilities, and retains list_patterns readout of the applied deterministic reliability patterns. Every operation is fixed-rule code with no LLM in the loop, and a safety/regulated-tagged prompt is refused storage unless a human review artifact (reviewer_id, passed adversarial test, failure modes, usage examples) is supplied. That refusal is surfaced as a structured blocked-escalated envelope with warning_card and evidence rather than cosmetic success.
MVP production caveat
align_prompt_library is suitable for pilot and launch-plan use as a practical MCP-accessible prompt library, but it is not yet a fully polished production service. Before relying on it for paid or regulated customer workflows, run a smoke test through the actual MCP install/server path, verify the SQLite database location and backup policy, and confirm any existing prompt-library databases have been migrated or reseeded. The component now has persistence, capability discovery, version history, rollback, validation, tag filtering, and clearer error behavior, but the surrounding install/docs/migration experience still needs final launch hardening.
When to use:
- Centralising all prompt templates used by a pipeline, with version history
- Rendering parameterised prompts at runtime without string formatting scattered across the codebase
- Searching and filtering prompts by tag or category before injection into an agent
Example:
from mvp.align_prompt_library import AlignPromptLibraryBlock, PromptLibraryInput
block = AlignPromptLibraryBlock(name="prompts")
block.infer(PromptLibraryInput(op="store", name="greeter", content="Hello, {{name}}!"))
result = block.infer(PromptLibraryInput(op="render", name="greeter", render_values={"name": "Alice"}))
# result.value.rendered → "Hello, Alice!"
Works well with: align_artifacts, align_specs, llm_router
Public API¶
AlignmentBlock(AIBlock[AlignmentSpecInput, AlignmentSpecOutput, dict])¶
In-memory alignment specification store.
| Field | Type | Default |
|---|---|---|
name | str | 'alignment_block' |
resource_bounds | ResourceBounds \| None | None |
usage | ResourceUsage | field(default_factory=ResourceUsage) |
db_path | str \| None | None |
Methods:
infer(data: AlignmentSpecInput) -> Result[AlignmentSpecOutput]¶
AlignmentSpecType(str, Enum)¶
RICEPrinciple(str, Enum)¶
AlignmentFailureMode(BaseModel)¶
A documented failure mode specific to an alignment specification.
| Field | Type | Default |
|---|---|---|
name | str | required |
description | str | required |
alignment_failure_type | Literal['outer', 'inner'] | 'outer' |
severity | Literal['low', 'medium', 'high', 'critical'] | 'medium' |
mitigation | str | '' |
detection_prompt | str | '' |
example | str | '' |
AlignmentTestCase(BaseModel)¶
A concrete test case for an alignment specification.
| Field | Type | Default |
|---|---|---|
id | str | '' |
input_description | str | required |
expected_behavior | str | required |
prohibited_behavior | str | '' |
enforcement_check | str | '' |
passes | bool \| None | None |
EnforcementMechanism(BaseModel)¶
A mechanism that enforces an alignment specification.
| Field | Type | Default |
|---|---|---|
mechanism_type | Literal['prompt', 'code', 'rlhf', 'rule', 'constitution'] | 'prompt' |
content | str | required |
description | str | '' |
applies_at | Literal['training', 'inference', 'both'] | 'inference' |
AlignmentSpec(BaseModel)¶
A formal alignment specification for a goal.
| Field | Type | Default |
|---|---|---|
id | str | '' |
name | str | required |
spec_type | AlignmentSpecType | AlignmentSpecType.SAFETY_CONSTRAINT |
version | int | 1 |
description | str | '' |
natural_language_spec | str | '' |
formal_spec | str | '' |
outer_alignment_goal | str | '' |
inner_alignment_notes | str | '' |
rice_principles | list[RICEPrinciple] | Field(default_factory=list) |
enforcement_mechanisms | list[EnforcementMechanism] | Field(default_factory=list) |
test_cases | list[AlignmentTestCase] | Field(default_factory=list) |
failure_modes | list[AlignmentFailureMode] | Field(default_factory=list) |
tags | list[str] | Field(default_factory=list) |
category | str | 'general' |
domain | str | '' |
recommended_backends | list[str] | Field(default_factory=list) |
goal_key | str | '' |
created_at | str | '' |
updated_at | str | '' |
author | str \| None | None |
metadata | dict[str, str] | Field(default_factory=dict) |
AlignedGoalNode(BaseModel)¶
A single node in an AlignedGoalTree.
| Field | Type | Default |
|---|---|---|
goal | str | required |
spec_name | str | '' |
depth | int | 0 |
parent_goal | str \| None | None |
child_goals | list[str] | Field(default_factory=list) |
AlignedGoalTree(BaseModel)¶
A goal tree where each node maps a goal (str key) to an AlignmentSpec (value).
| Field | Type | Default |
|---|---|---|
id | str | '' |
name | str | required |
root_goal | str | required |
nodes | dict[str, AlignedGoalNode] | Field(default_factory=dict) |
specs | dict[str, AlignmentSpec] | Field(default_factory=dict) |
metadata | dict[str, str] | Field(default_factory=dict) |
created_at | str | '' |
updated_at | str | '' |
AlignmentSpecInput(BaseModel)¶
Input to AlignmentBlock.
| Field | Type | Default |
|---|---|---|
op | Literal['store', 'retrieve', 'list', 'delete', 'search', 'validate', 'create_tree', 'get_tree', 'capabilities'] | required |
name | str | '' |
spec_type | AlignmentSpecType | AlignmentSpecType.SAFETY_CONSTRAINT |
description | str | '' |
natural_language_spec | str | '' |
formal_spec | str | '' |
outer_alignment_goal | str | '' |
inner_alignment_notes | str | '' |
rice_principles | list[RICEPrinciple] | Field(default_factory=list) |
enforcement_mechanisms | list[dict] | Field(default_factory=list) |
test_cases | list[dict] | Field(default_factory=list) |
failure_modes | list[dict] | Field(default_factory=list) |
tags | list[str] | Field(default_factory=list) |
category | str | 'general' |
domain | str | '' |
recommended_backends | list[str] | Field(default_factory=list) |
goal_key | str | '' |
author | str \| None | None |
metadata | dict[str, str] | Field(default_factory=dict) |
query | str | '' |
tree_name | str | '' |
root_goal | str | '' |
goal_spec_pairs | list[dict] | Field(default_factory=list) |
AlignmentSpecOutput(BaseModel)¶
Output from AlignmentBlock.
| Field | Type | Default |
|---|---|---|
op | str | required |
specs | list[AlignmentSpec] | Field(default_factory=list) |
retrieved | AlignmentSpec \| None | None |
tree | AlignedGoalTree \| None | None |
message | str | '' |
degraded | bool | False |
degradation_reason | str | '' |
completion_state | Literal['verified', 'qualified-draft', 'blocked-escalated', 'failed'] | 'qualified-draft' |
warning_card | str \| None | None |
evidence | dict[str, Any] | Field(default_factory=dict) |
request_id | str \| None | None |
run_id | str \| None | None |
MissingVariableError(ValueError)¶
Raised when a required template variable is absent in strict rendering mode.
Constructor:
| Parameter | Type | Default |
|---|---|---|
missing | list[str] | required |
template | str | required |
AlignPromptLibraryBlock(AIBlock[PromptLibraryInput, PromptLibraryOutput, dict])¶
Versioned prompt store.
| Field | Type | Default |
|---|---|---|
name | str | 'align_prompt_library' |
resource_bounds | ResourceBounds \| None | None |
usage | ResourceUsage | field(default_factory=ResourceUsage) |
db_path | str \| None | None |
Methods:
infer(data: PromptLibraryInput) -> Result[PromptLibraryOutput]¶
TemplateVariable(BaseModel)¶
A template variable declared in a PromptEntry.
| Field | Type | Default |
|---|---|---|
name | str | required |
type_hint | str | 'str' |
description | str | '' |
default | str \| None | None |
required | bool | True |
example | str \| None | None |
UsageExample(BaseModel)¶
A worked example showing a prompt in action.
| Field | Type | Default |
|---|---|---|
title | str | required |
description | str | '' |
input_values | dict[str, str] | Field(default_factory=dict) |
rendered_output | str | '' |
notes | str \| None | None |
FailureMode(BaseModel)¶
A documented failure mode for a prompt.
| Field | Type | Default |
|---|---|---|
name | str | required |
description | str | required |
severity | Literal['low', 'medium', 'high', 'critical'] | 'medium' |
mitigation | str | '' |
PromptEntry(BaseModel)¶
A single versioned prompt with full metadata.
| Field | Type | Default |
|---|---|---|
id | str | '' |
name | str | required |
content | str | required |
description | str | '' |
safety_tag | PromptSafetyTag | 'general' |
reviewer_id | str | '' |
adversarial_test_status | AdversarialTestStatus | 'untested' |
version | int | 1 |
tags | list[str] | Field(default_factory=list) |
category | str | 'general' |
variables | list[TemplateVariable] | Field(default_factory=list) |
usage_examples | list[UsageExample] | Field(default_factory=list) |
failure_modes | list[FailureMode] | Field(default_factory=list) |
recommended_backends | list[str] | Field(default_factory=list) |
created_at | str | '' |
updated_at | str | '' |
author | str \| None | None |
metadata | dict[str, str] | Field(default_factory=dict) |
PromptLibraryInput(BaseModel)¶
Input to AlignPromptLibraryBlock.
| Field | Type | Default |
|---|---|---|
op | Literal['store', 'retrieve', 'list', 'delete', 'search', 'render', 'validate', 'capabilities'] | required |
name | str | '' |
content | str | '' |
tags | list[str] | Field(default_factory=list) |
query | str | '' |
category | str | '' |
description | str | '' |
variables | list[TemplateVariable] | Field(default_factory=list) |
usage_examples | list[UsageExample] | Field(default_factory=list) |
failure_modes | list[FailureMode] | Field(default_factory=list) |
recommended_backends | list[str] | Field(default_factory=list) |
author | str \| None | None |
metadata | dict[str, str] | Field(default_factory=dict) |
render_values | dict[str, str] | Field(default_factory=dict) |
safety_tag | PromptSafetyTag | 'general' |
reviewer_id | str | '' |
adversarial_test_status | AdversarialTestStatus | 'untested' |
PromptLibraryOutput(BaseModel)¶
Output from AlignPromptLibraryBlock.
| Field | Type | Default |
|---|---|---|
op | str | required |
prompts | list[PromptEntry] | Field(default_factory=list) |
retrieved | PromptEntry \| None | None |
rendered | str | '' |
variables_found | list[str] | Field(default_factory=list) |
message | str | '' |
degraded | bool | False |
degradation_reason | str | '' |
completion_state | Literal['verified', 'qualified-draft', 'blocked-escalated', 'failed'] | 'qualified-draft' |
warning_card | str \| None | None |
evidence | dict[str, Any] | Field(default_factory=dict) |
request_id | str \| None | None |
run_id | str \| None | None |
AlignPromptLibraryMCPBlock(AIBlock[MCPPromptLibraryInput, MCPPromptLibraryOutput, dict])¶
| Field | Type | Default |
|---|---|---|
name | str | 'align_prompt_library_mcp' |
state | dict \| None | None |
db_path | str | ':memory:' |
resource_bounds | ResourceBounds \| None | None |
usage | ResourceUsage | field(default_factory=ResourceUsage) |
Methods:
infer(inp: MCPPromptLibraryInput) -> Result[MCPPromptLibraryOutput]¶
MCPPromptLibraryInput(BaseModel)¶
| Field | Type | Default |
|---|---|---|
op | PromptLibraryMCPOp | required |
prompt_id | str \| None | None |
prompt_name | str \| None | None |
template | str \| None | None |
variables | dict[str, Any] | Field(default_factory=dict) |
tags | list[str] | Field(default_factory=list) |
category | str \| None | None |
description | str \| None | None |
spec_id | str \| None | None |
spec_name | str \| None | None |
spec_type | str \| None | None |
spec_content | str \| None | None |
spec_constraints | list[str] | Field(default_factory=list) |
tree_id | str \| None | None |
tree_name | str \| None | None |
tree_goal | str \| None | None |
version | int \| None | None |
target_spec_id | str \| None | None |
items | list[dict[str, Any]] | Field(default_factory=list) |
content | str \| None | None |
query | str \| None | None |
limit | int | 20 |
metadata | dict[str, Any] | Field(default_factory=dict) |
MCPPromptLibraryOutput(BaseModel)¶
| Field | Type | Default |
|---|---|---|
op | str | required |
success | bool | required |
prompt_id | str \| None | None |
prompt | dict[str, Any] \| None | None |
prompts | list[dict[str, Any]] | Field(default_factory=list) |
rendered | str \| None | None |
spec_id | str \| None | None |
spec | dict[str, Any] \| None | None |
specs | list[dict[str, Any]] | Field(default_factory=list) |
tree_id | str \| None | None |
tree | dict[str, Any] \| None | None |
trees | list[dict[str, Any]] | Field(default_factory=list) |
versions | list[dict[str, Any]] | Field(default_factory=list) |
links | list[dict[str, Any]] | Field(default_factory=list) |
count | int | 0 |
stats | dict[str, Any] | Field(default_factory=dict) |
message | str | '' |
error | str | '' |
valid | bool | False |
degraded | bool | False |
degradation_reason | str | '' |
completion_state | Literal['verified', 'qualified-draft', 'blocked-escalated', 'failed'] | 'qualified-draft' |
warning_card | str \| None | None |
evidence | dict[str, Any] | Field(default_factory=dict) |
request_id | str \| None | None |
run_id | str \| None | None |
MCP Tools¶
| Operation | Source |
|---|---|
store | prompt_library_mcp |
retrieve | prompt_library_mcp |
list | prompt_library_mcp |
delete | prompt_library_mcp |
search | prompt_library_mcp |
render | prompt_library_mcp |
validate | prompt_library_mcp |
store_spec | prompt_library_mcp |
retrieve_spec | prompt_library_mcp |
list_specs | prompt_library_mcp |
delete_spec | prompt_library_mcp |
search_specs | prompt_library_mcp |
validate_spec | prompt_library_mcp |
create_tree | prompt_library_mcp |
get_tree | prompt_library_mcp |
list_trees | prompt_library_mcp |
list_versions | prompt_library_mcp |
rollback | prompt_library_mcp |
export_json | prompt_library_mcp |
import_json | prompt_library_mcp |
bulk_store | prompt_library_mcp |
link_to_spec | prompt_library_mcp |
get_linked | prompt_library_mcp |
capabilities | prompt_library_mcp |
stats | prompt_library_mcp |
info | prompt_library_mcp |
list_patterns | prompt_library_mcp |