Index
prompts
¶
Prompt templating for Marianne jobs.
Handles Jinja2 templates, completion prompt generation, and dynamic preambles.
Classes¶
CompletionContext
dataclass
¶
CompletionContext(sheet_num, total_sheets, passed_validations, failed_validations, completion_attempt, max_completion_attempts, original_prompt, workspace)
Context for generating completion prompts.
Uses ValidationResult objects (not just ValidationRule) to ensure that file paths are properly expanded with actual values like workspace and sheet_num, rather than showing template placeholders.
PromptBuilder
¶
Builds prompts including completion prompts for partial recovery.
Handles Jinja2 template rendering and auto-generation of completion prompts when a sheet partially completes.
Initialize prompt builder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
PromptConfig
|
Prompt configuration from job config. |
required |
jinja_env
|
Environment | None
|
Optional custom Jinja2 environment. |
None
|
Source code in src/marianne/prompts/templating.py
Methods:¶
build_sheet_context
¶
Build sheet context from job parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sheet_num
|
int
|
Current sheet number (1-indexed). |
required |
total_sheets
|
int
|
Total number of sheets. |
required |
sheet_size
|
int
|
Items per sheet. |
required |
total_items
|
int
|
Total items to process. |
required |
start_item
|
int
|
First item number (1-indexed). |
required |
workspace
|
Path
|
Workspace directory. |
required |
Returns:
| Type | Description |
|---|---|
SheetContext
|
SheetContext with calculated item range. |
Source code in src/marianne/prompts/templating.py
build_sheet_prompt
¶
build_sheet_prompt(context, patterns=None, validation_rules=None, failure_history=None, spec_fragments=None, raw_prompt=False)
Build the standard sheet prompt from config.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
SheetContext
|
Sheet context with item range and workspace. |
required |
patterns
|
list[str] | None
|
Optional list of learned pattern descriptions to inject. |
None
|
validation_rules
|
list[ValidationRule] | None
|
Optional list of validation rules to inject as requirements. These are the rules that will be checked after sheet execution - injecting them helps Claude understand exactly what success looks like. |
None
|
failure_history
|
list[HistoricalFailure] | None
|
Optional list of historical failures from previous sheets. Injected to help Claude learn from past mistakes and avoid repeating the same errors (Evolution v6). |
None
|
spec_fragments
|
list[SpecFragment] | None
|
Optional list of spec corpus fragments to inject as project context. Fragments are inserted after injected context and before failure history per the prompt assembly order (Phase 1: Spec Corpus Pipeline). |
None
|
raw_prompt
|
bool
|
When True, render the Jinja template against the
sheet context and return immediately — skipping every
wrapping layer (skills, tools, injected context, spec
fragments, failure history, patterns, validations). Honored
when the instrument profile declares |
False
|
Returns:
| Type | Description |
|---|---|
str
|
Rendered prompt string. |
Source code in src/marianne/prompts/templating.py
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 | |
build_completion_prompt
¶
Generate auto-completion prompt for partial failures.
This prompt tells the agent: 1. What validations already passed (don't redo) 2. What validations failed (focus on these) 3. Semantic hints for focused recovery 4. Clear instruction to complete only missing items
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
CompletionContext
|
Completion context with passed/failed validations. |
required |
semantic_hints
|
list[str] | None
|
Optional list of actionable hints from semantic validation analysis. These are suggested fixes derived from the failure_category and suggested_fix fields of failed ValidationResults. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Completion prompt string. |
Source code in src/marianne/prompts/templating.py
SheetContext
dataclass
¶
SheetContext(sheet_num, total_sheets, start_item, end_item, workspace, score_dir='', instrument_name='', instrument_alias='', stage=0, instance=1, fan_count=1, total_stages=0, mailbox_path='', mailbox_siblings=dict(), previous_outputs=dict(), previous_files=dict(), skipped_upstream=list(), injected_context=list(), injected_skills=list(), injected_tools=list(), delivery_manifest=list(), receipt_sources=list(), native_execution=None)
Context for building a sheet prompt.
Includes both sheet-level metadata and optional cross-sheet context from previous sheet executions. Fan-out metadata (stage, instance, fan_count, total_stages) is populated when fan_out is configured.
Attributes¶
stage
class-attribute
instance-attribute
¶
Logical stage number (1-indexed). 0 = not set, falls back to sheet_num.
instance
class-attribute
instance-attribute
¶
Instance within fan-out group (1-indexed). Default 1.
fan_count
class-attribute
instance-attribute
¶
Total instances in this stage's fan-out group. Default 1.
total_stages
class-attribute
instance-attribute
¶
Original stage count before expansion. 0 = not set, falls back to total_sheets.
mailbox_path
class-attribute
instance-attribute
¶
Scratch-owned inbox root, empty when messaging is disabled.
mailbox_siblings
class-attribute
instance-attribute
¶
Same-movement sheet numbers and human-readable labels.
previous_outputs
class-attribute
instance-attribute
¶
Stdout outputs from previous sheets. Keys are sheet numbers (1-indexed).
previous_files
class-attribute
instance-attribute
¶
File contents captured between sheets. Keys are file paths.
skipped_upstream
class-attribute
instance-attribute
¶
Sheet numbers of upstream sheets that were skipped (#120). Allows prompts to handle incomplete fan-in data explicitly.
injected_context
class-attribute
instance-attribute
¶
Resolved content from 'context' category injections.
injected_skills
class-attribute
instance-attribute
¶
Resolved content from 'skill' category injections.
injected_tools
class-attribute
instance-attribute
¶
Resolved content from 'tool' category injections.
delivery_manifest
class-attribute
instance-attribute
¶
Hash-only provenance for bytes assembled into this sheet's prompt.
receipt_sources
class-attribute
instance-attribute
¶
Ordered PromptReceiptSource records, delivered and dropped (GH #546).
native_execution
class-attribute
instance-attribute
¶
Conductor execution facts, not authorization or an authenticated credential.
Methods:¶
to_dict
¶
Convert to dictionary for template rendering.
Provides both old terminology (stage, instance, fan_count, total_stages) and new terminology (movement, voice, voice_count, total_movements) so templates can use either vocabulary. Matches Sheet.template_variables().
Source code in src/marianne/prompts/templating.py
Functions:¶
build_preamble
¶
build_preamble(sheet_num, total_sheets, workspace, retry_count=0, is_parallel=False, healing_context=None)
Build a context-aware preamble for a Marianne-orchestrated agent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sheet_num
|
int
|
Current sheet number (1-indexed). |
required |
total_sheets
|
int
|
Total number of sheets in the concert. |
required |
workspace
|
Path
|
Workspace directory path. |
required |
retry_count
|
int
|
Number of previous failed attempts (0 = first run). |
0
|
is_parallel
|
bool
|
Whether parallel execution is enabled. |
False
|
healing_context
|
dict[str, Any] | None
|
Failure signals from the prior attempt (#201). When
present on a retry, rendered into a bounded UNTRUSTED-EVIDENCE block
so the agent knows specifically what failed instead of retrying
blind. Carries the raw |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Preamble string wrapped in |
Source code in src/marianne/prompts/preamble.py
build_sheet_prompt_simple
¶
build_sheet_prompt_simple(config, sheet_num, total_sheets, sheet_size, total_items, start_item, workspace)
Convenience function to build a sheet prompt.
This provides a simpler interface for cases where you don't need to reuse the PromptBuilder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
PromptConfig
|
Prompt configuration. |
required |
sheet_num
|
int
|
Current sheet number. |
required |
total_sheets
|
int
|
Total number of sheets. |
required |
sheet_size
|
int
|
Items per sheet. |
required |
total_items
|
int
|
Total items. |
required |
start_item
|
int
|
First item number. |
required |
workspace
|
Path
|
Workspace directory. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Rendered prompt string. |