templating
templating
¶
Prompt templating for Marianne jobs.
Handles building sheet prompts from templates and generating auto-completion prompts for partial sheet recovery.
Attributes¶
Classes¶
SheetContext
dataclass
¶
SheetContext(sheet_num, total_sheets, start_item, end_item, workspace, stage=0, instance=1, fan_count=1, total_stages=0, previous_outputs=dict(), previous_files=dict(), skipped_upstream=list(), injected_context=list(), injected_skills=list(), injected_tools=list())
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.
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.
Functions¶
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
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
Functions¶
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)
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
|
Returns:
| Type | Description |
|---|---|
str
|
Rendered prompt string. |
Source code in src/marianne/prompts/templating.py
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 | |
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
Functions¶
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. |