preflight
preflight
¶
Pre-flight checks and prompt analysis before sheet execution.
Analyzes prompts before execution to estimate token usage, extract file references, and detect potential issues early.
Classes¶
PromptMetrics
dataclass
¶
PromptMetrics(character_count, estimated_tokens, line_count, has_file_references, referenced_paths=list(), word_count=0)
Metrics about a prompt for monitoring and optimization.
Provides visibility into prompt size and complexity before execution.
Attributes¶
estimated_tokens
instance-attribute
¶
Estimated token count via centralized estimator (tokens.estimate_tokens).
has_file_references
instance-attribute
¶
Whether the prompt contains file path references.
referenced_paths
class-attribute
instance-attribute
¶
List of file paths extracted from the prompt.
word_count
class-attribute
instance-attribute
¶
Approximate word count for additional context.
Functions¶
from_prompt
classmethod
¶
Analyze a prompt and extract metrics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt
|
str
|
The prompt text to analyze. |
required |
Returns:
| Type | Description |
|---|---|
PromptMetrics
|
PromptMetrics with extracted data. |
Source code in src/marianne/execution/preflight.py
to_dict
¶
Convert to serializable dictionary.
Source code in src/marianne/execution/preflight.py
PreflightResult
dataclass
¶
PreflightResult(prompt_metrics, warnings=list(), errors=list(), paths_accessible=dict(), working_directory_valid=True)
Result of pre-flight checks before sheet execution.
Captures both prompt metrics and any warnings/errors that should be addressed before or during execution.
Attributes¶
warnings
class-attribute
instance-attribute
¶
Non-fatal warnings that should be logged but don't block execution.
errors
class-attribute
instance-attribute
¶
Fatal issues that should prevent execution.
paths_accessible
class-attribute
instance-attribute
¶
Mapping of referenced paths to their accessibility status.
working_directory_valid
class-attribute
instance-attribute
¶
Whether the working directory exists and is accessible.
Functions¶
to_dict
¶
Convert to serializable dictionary.
Source code in src/marianne/execution/preflight.py
PreflightChecker
¶
PreflightChecker(workspace, working_directory=None, token_warning_threshold=TOKEN_WARNING_THRESHOLD, token_error_threshold=TOKEN_ERROR_THRESHOLD)
Performs pre-flight checks before sheet execution.
Analyzes prompts for potential issues, verifies file references, and provides warnings for resource-intensive prompts.
Initialize preflight checker.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workspace
|
Path
|
Base workspace directory for resolving relative paths. |
required |
working_directory
|
Path | None
|
Working directory for execution (defaults to workspace). |
None
|
token_warning_threshold
|
int
|
Token count above which to warn. |
TOKEN_WARNING_THRESHOLD
|
token_error_threshold
|
int
|
Token count above which to error. |
TOKEN_ERROR_THRESHOLD
|
Source code in src/marianne/execution/preflight.py
Functions¶
check
¶
Perform pre-flight checks on a prompt.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt
|
str
|
The prompt text to analyze. |
required |
sheet_context
|
dict[str, Any] | None
|
Optional context for template variable expansion. |
None
|
Returns:
| Type | Description |
|---|---|
PreflightResult
|
PreflightResult with metrics, warnings, and errors. |
Source code in src/marianne/execution/preflight.py
Functions¶
run_preflight_check
¶
Convenience function to run preflight checks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt
|
str
|
The prompt text to analyze. |
required |
workspace
|
Path
|
Base workspace directory. |
required |
working_directory
|
Path | None
|
Optional working directory for execution. |
None
|
sheet_context
|
dict[str, Any] | None
|
Optional context for template expansion. |
None
|
Returns:
| Type | Description |
|---|---|
PreflightResult
|
PreflightResult with metrics and any warnings/errors. |