Index
validation
¶
Enhanced validation module for Marianne job configurations.
This module provides comprehensive validation beyond Pydantic schema validation, including Jinja template syntax checking, path existence validation, regex pattern compilation, and cross-reference checks.
The validation system is designed for two use cases:
1. Pre-execution validation via mzt validate command
2. Self-healing diagnosis to identify fixable configuration issues
Example usage
from marianne.validation import ValidationRunner, create_default_checks
runner = ValidationRunner(create_default_checks()) issues = runner.validate(config, config_path, raw_yaml)
for issue in issues: print(f"[{issue.severity}] {issue.check_id}: {issue.message}")
Classes¶
ValidationCheck
¶
Bases: Protocol
Protocol for configuration validation checks.
Each check examines a specific aspect of the configuration and returns a list of ValidationIssue objects (empty if check passes).
Checks should be: - Idempotent (safe to run multiple times) - Side-effect free (don't modify anything) - Fast (validation should complete quickly)
Attributes¶
Methods:¶
check
¶
Run the validation check.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
JobConfig
|
Parsed JobConfig object (already validated by Pydantic) |
required |
config_path
|
Path
|
Path to the config file (for resolving relative paths) |
required |
raw_yaml
|
str
|
Raw YAML text (for line number extraction) |
required |
Returns:
| Type | Description |
|---|---|
list[ValidationIssue]
|
List of ValidationIssue objects (empty if check passes) |
Source code in src/marianne/validation/base.py
ValidationIssue
dataclass
¶
ValidationIssue(check_id, severity, message, line=None, column=None, context=None, suggestion=None, auto_fixable=False, metadata=dict())
A single validation issue found in the configuration.
Attributes:
| Name | Type | Description |
|---|---|---|
check_id |
str
|
Unique identifier for the check (e.g., V001, V101) |
severity |
ValidationSeverity
|
ERROR, WARNING, or INFO |
message |
str
|
Human-readable description of the issue |
line |
int | None
|
Line number in config file (if applicable) |
column |
int | None
|
Column number (if applicable) |
context |
str | None
|
Surrounding text for context |
suggestion |
str | None
|
How to fix the issue |
auto_fixable |
bool
|
Whether --self-healing can automatically fix this |
ValidationSeverity
¶
Bases: str, Enum
Severity level for validation issues.
- ERROR: Must fix before execution - job will fail
- WARNING: Should fix - may cause runtime failures
- INFO: Informational - consider reviewing
ValidationReporter
¶
Formats and outputs validation results.
Supports multiple output formats: - Terminal output with colors (default) - JSON for machine parsing - Plain text for logs
Initialize reporter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
console
|
Console | None
|
Rich Console for output. Creates one if not provided. |
None
|
Source code in src/marianne/validation/reporter.py
Methods:¶
report_terminal
¶
Output validation results to terminal with formatting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
issues
|
list[ValidationIssue]
|
List of validation issues |
required |
config_name
|
str
|
Name of the config being validated |
required |
show_passed
|
bool
|
Whether to show passed checks summary |
True
|
Source code in src/marianne/validation/reporter.py
report_json
¶
Output validation results as JSON.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
issues
|
list[ValidationIssue]
|
List of validation issues |
required |
Returns:
| Type | Description |
|---|---|
str
|
JSON string representation |
Source code in src/marianne/validation/reporter.py
report_rendering_terminal
¶
Output a rendering preview to the terminal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
preview
|
RenderingPreview
|
The rendering preview to display. |
required |
verbose
|
bool
|
If False, show sheet 1 only. If True, show all sheets. |
False
|
Source code in src/marianne/validation/reporter.py
report_rendering_json
¶
Return a rendering preview as a JSON-serializable dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
preview
|
RenderingPreview
|
The rendering preview to serialize. |
required |
full_prompts
|
bool
|
Also emit each sheet's complete |
False
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict with total_sheets, has_fan_out, has_dependencies, |
dict[str, Any]
|
render_errors, and a sheets array. |
Source code in src/marianne/validation/reporter.py
format_plain
¶
Format issues as plain text for logs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
issues
|
list[ValidationIssue]
|
List of validation issues |
required |
Returns:
| Type | Description |
|---|---|
str
|
Plain text representation |
Source code in src/marianne/validation/reporter.py
ValidationRunner
¶
Orchestrates validation checks against a configuration.
The runner collects issues from all checks, sorts them by severity, and provides summary information for reporting.
Initialize with a list of checks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
checks
|
list[ValidationCheck] | None
|
List of validation checks to run. If None, uses default checks. |
None
|
Source code in src/marianne/validation/runner.py
Methods:¶
add_check
¶
validate
¶
Run all validation checks against the configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
JobConfig
|
Parsed JobConfig object |
required |
config_path
|
Path
|
Path to the config file |
required |
raw_yaml
|
str
|
Raw YAML text for line number extraction |
required |
Returns:
| Type | Description |
|---|---|
list[ValidationIssue]
|
List of all issues found, sorted by severity (errors first) |
Source code in src/marianne/validation/runner.py
get_exit_code
¶
Determine exit code based on issues found.
Returns:
| Name | Type | Description |
|---|---|---|
0 |
int
|
No errors (warnings/info OK) |
1 |
int
|
One or more ERROR-severity issues |
Source code in src/marianne/validation/runner.py
has_errors
¶
count_by_severity
¶
Count issues by severity level.
Source code in src/marianne/validation/runner.py
Functions:¶
create_default_checks
¶
Create the default set of validation checks.
Returns all built-in checks in recommended execution order.
Source code in src/marianne/validation/runner.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 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 | |