Prompts¶
Utilities for loading and rendering Jinja prompt templates with strict
undefined-variable behaviour: a reference to a missing context variable raises
TemplateError rather than rendering a silently incomplete prompt. AnalysisMode
selects the template subdirectory (agentic or single_turn). See
Architecture for how processors assemble prompts.
prompts ¶
Prompt loading utilities for GAZE.
Provides Jinja2 template loading and rendering for system and task prompts. Dataset-specific implementations should provide their own prompts directory.
Templates use strict undefined variable behavior: any reference to a variable
not present in the context dict will raise TemplateError immediately, preventing
silent generation of incomplete prompts.
AnalysisMode ¶
Bases: str, Enum
Analysis modes for prompt generation.
Inherits from str for easy comparison with string values.
Source code in src/gaze/prompts/__init__.py
load_template ¶
Load and render a Jinja template with the given context.
Uses strict undefined variable behavior: any variable referenced in the
template but missing from context will raise TemplateError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
template_path
|
Path
|
Path to the Jinja template file |
required |
context
|
dict[str, Any]
|
Dictionary of variables for template rendering |
required |
Returns:
| Type | Description |
|---|---|
str
|
Rendered template string |
Raises:
| Type | Description |
|---|---|
TemplateError
|
If template file doesn't exist, a required variable is missing, or rendering fails for any other reason. |
Example
from pathlib import Path from gaze.prompts import load_template
prompt = load_template( Path("prompts/system.jinja"), {"task": "diagnosis", "modality": "MRI"} )
Source code in src/gaze/prompts/__init__.py
load_prompt ¶
Load and render a prompt template from a prompts directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompts_dir
|
Path
|
Base directory containing mode subdirectories |
required |
template_name
|
str
|
Name of the template file (e.g., 'task.jinja') |
required |
mode
|
str
|
Analysis mode ('agentic' or 'single_turn') |
required |
context
|
dict[str, Any]
|
Dictionary of variables for template rendering |
required |
Returns:
| Type | Description |
|---|---|
str
|
Rendered prompt string |
Raises:
| Type | Description |
|---|---|
ValueError
|
If mode directory doesn't exist |
TemplateError
|
If template file doesn't exist or rendering fails |
Source code in src/gaze/prompts/__init__.py
combine_prompts ¶
Combine system prompt with task-specific prompt.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system_prompt
|
str
|
The base system prompt |
required |
task_prompt
|
str
|
The task-specific prompt |
required |
mode
|
str
|
Analysis mode string (must be valid AnalysisMode value) |
required |
Returns:
| Type | Description |
|---|---|
str
|
Combined prompt string |
Raises:
| Type | Description |
|---|---|
ValueError
|
If mode is not a valid AnalysisMode |
Source code in src/gaze/prompts/__init__.py
create_prompt ¶
create_prompt(
prompts_dir: Path,
mode: str,
context: dict[str, Any],
template_name: str = "task.jinja",
) -> str
Create a complete prompt by combining system and task prompts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompts_dir
|
Path
|
Base directory containing mode subdirectories |
required |
mode
|
str
|
Analysis mode ('agentic' or 'single_turn') |
required |
context
|
dict[str, Any]
|
Dictionary of variables for template rendering. Standard context variables for generic GAZE templates: - domain_expertise: Domain-specific expertise description - analysis_workflow: Domain-specific analysis workflow steps - task_instructions: The specific task to perform - image_info: Information about the image (dimensions, etc.) - context: Additional context (e.g., clinical history) - output_format: Description of expected output format Note: Tool documentation is injected automatically by
|
required |
template_name
|
str
|
Name of the task template (default: 'task.jinja') |
'task.jinja'
|
Returns:
| Type | Description |
|---|---|
str
|
Complete combined prompt string |
Example
from gaze.prompts import create_prompt
prompt = create_prompt( prompts_dir=Path("my_prompts"), mode="agentic", context={ "domain_expertise": "You are an expert radiologist...", "task_instructions": "Analyze this brain MRI...", }, )