outcomes
outcomes
¶
Outcome recording and pattern detection for learning.
Attributes¶
Classes¶
SheetOutcome
dataclass
¶
SheetOutcome(sheet_id, job_id, validation_results, execution_duration, retry_count, completion_mode_used, final_status, validation_pass_rate, success_without_retry, patterns_detected=list(), timestamp=(lambda: now(tz=UTC))(), failure_category_counts=dict(), semantic_patterns=list(), fix_suggestions=list(), patterns_applied=list(), stdout_tail='', stderr_tail='', error_history=list(), grounding_passed=None, grounding_confidence=None, grounding_guidance=None)
Structured outcome data from a completed sheet execution.
This dataclass captures all relevant information about a sheet execution for learning and pattern detection purposes.
Attributes¶
failure_category_counts
class-attribute
instance-attribute
¶
Counts of each failure category from validation results.
Example: {'missing': 2, 'stale': 1, 'malformed': 0} Categories: missing, malformed, incomplete, stale, error
semantic_patterns
class-attribute
instance-attribute
¶
Extracted semantic patterns from failure_reason fields.
Example: ['file not created', 'pattern not found', 'content empty'] These are normalized phrases that can be aggregated across outcomes.
fix_suggestions
class-attribute
instance-attribute
¶
Collected suggested_fix values from failed validations.
Example: ['Ensure file is created in workspace/', 'Add missing import']
patterns_applied
class-attribute
instance-attribute
¶
Pattern descriptions that were applied/injected for this sheet execution.
These are the patterns from get_relevant_patterns() that were included in the prompt. Used for effectiveness tracking: correlate patterns_applied with success_without_retry to measure which patterns actually help.
Example: ['⚠️ Common issue: file_exists validation tends to fail (seen 3x)']
stdout_tail
class-attribute
instance-attribute
¶
Captured tail of stdout from execution.
Stores the last N characters of stdout for pattern extraction. Used by OutputPatternExtractor to detect error patterns.
stderr_tail
class-attribute
instance-attribute
¶
Captured tail of stderr from execution.
Stores the last N characters of stderr for pattern extraction. Used by OutputPatternExtractor to detect error patterns.
error_history
class-attribute
instance-attribute
¶
History of errors encountered during execution.
Each entry is a dict with error_code, category, message, etc. Used by _detect_error_code_patterns() for recurring error analysis.
Example: [{'error_code': 'E009', 'category': 'transient', 'message': 'Rate limited'}]
grounding_passed
class-attribute
instance-attribute
¶
Whether all grounding hooks passed (None if grounding not enabled).
Used to correlate grounding outcomes with validation results and pattern effectiveness over time.
grounding_confidence
class-attribute
instance-attribute
¶
Average confidence across grounding hooks (0.0-1.0, None if not enabled).
Higher confidence means external validators had high certainty in their results. Can be correlated with success_without_retry to identify reliable grounding sources.
grounding_guidance
class-attribute
instance-attribute
¶
Recovery guidance from failed grounding hooks (None if passed or not enabled).
Captures actionable suggestions from external validators that failed, useful for pattern detection and learning what recovery strategies work.
OutcomeStore
¶
JsonOutcomeStore
¶
JSON-file based outcome store implementation.
Stores outcomes in a JSON file with atomic saves, following the same pattern as JsonStateBackend.
Initialize the JSON outcome store.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
store_path
|
Path
|
Path to the JSON file for storing outcomes. |
required |
Source code in src/marianne/learning/outcomes.py
Functions¶
record
async
¶
Record a sheet outcome to the store.
After recording, if there are enough outcomes (>= 5), pattern detection is run and patterns_detected is populated on the outcome.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
outcome
|
SheetOutcome
|
The sheet outcome to record. |
required |
Source code in src/marianne/learning/outcomes.py
query_similar
async
¶
Query for similar past outcomes.
Currently returns recent outcomes for the same job_id. Future: implement semantic similarity matching.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
dict[str, Any]
|
Context dict containing job_id and other metadata. |
required |
limit
|
int
|
Maximum number of outcomes to return. |
10
|
Returns:
| Type | Description |
|---|---|
list[SheetOutcome]
|
List of similar sheet outcomes. |
Source code in src/marianne/learning/outcomes.py
get_patterns
async
¶
Get detected patterns for a job.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_name
|
str
|
The job name to get patterns for. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of pattern strings detected across outcomes. |
Source code in src/marianne/learning/outcomes.py
detect_patterns
async
¶
Detect patterns from all recorded outcomes.
Uses PatternDetector to analyze historical outcomes and identify recurring patterns that can inform future executions. Results are cached and invalidated when outcomes change (record/load).
Returns:
| Type | Description |
|---|---|
list[DetectedPattern]
|
List of DetectedPattern objects sorted by confidence. |
Source code in src/marianne/learning/outcomes.py
get_relevant_patterns
async
¶
Get pattern descriptions relevant to the given context.
This method detects patterns, matches them to the context, and returns human-readable descriptions suitable for prompt injection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
dict[str, Any]
|
Context dict containing job_id, sheet_num, validation_types, etc. |
required |
limit
|
int
|
Maximum number of patterns to return. |
5
|
Returns:
| Type | Description |
|---|---|
list[str]
|
List of pattern description strings for prompt injection. |