API Reference
Top-level Exports
Confidence scoring and artifact review for the impact engine pipeline.
- class impact_engine_evaluate.EvaluateResult(initiative_id, confidence, confidence_range, strategy, report='')[source]
Output of the EVALUATE pipeline stage (both strategies).
- Parameters:
initiative_id (str) – Initiative identifier.
confidence (float) – Confidence score between 0.0 and 1.0.
confidence_range (tuple[float, float]) –
(lower, upper)bounds from the method reviewer.strategy (str) – Strategy that produced this result (
"score"or"review").report (str | ReviewResult) – Descriptive string for the score strategy; full
ReviewResultfor the review strategy.
- report: str | ReviewResult = ''
- impact_engine_evaluate.evaluate_confidence(config, job_dir, *, cost_to_scale=None)[source]
Evaluate the confidence of a job directory.
Reads the job directory, dispatches on
evaluate_strategyfrom the manifest, and returns anEvaluateResult. Both the deterministic score path and the LLM review path are supported — the manifest controls which is used.- Parameters:
config (str | Path | dict | None) – Backend configuration for the review strategy (path to a YAML file or an inline dict). Ignored for the score strategy.
job_dir (str | Path) – Path to the job directory containing
manifest.jsonand upstream artifacts.cost_to_scale (float | None) – Optional override for the initiative’s cost-to-scale value. When provided, replaces the value stored in the job directory artifacts before scoring.
- Returns:
Confidence score, strategy used, and a strategy-specific report. Also writes
evaluate_result.json(andscore_result.jsonfor the score strategy) to job_dir.- Return type:
Examples
>>> result = evaluate_confidence("review_config.yaml", "path/to/rct_job/") >>> print(result.confidence) 0.75
- class impact_engine_evaluate.MethodReviewer[source]
Base class for methodology-specific artifact reviewers.
Each method reviewer bundles its own prompt template, knowledge base content, and artifact loading logic. The default
load_artifactreads all files listed in the manifest and attempts to extractsample_sizefrom the first JSON file. Subclasses may override if they need method-specific loading.- confidence_range
(lower, upper)bounds for deterministic confidence scoring.
- load_artifact(manifest, job_dir)[source]
Read artifact files per manifest and return a payload.
The default implementation reads every file entry in manifest, concatenates their contents, and extracts
sample_sizefrom the first JSON file that contains one. Subclasses may override for method-specific loading.- Parameters:
manifest (Manifest) – Parsed job manifest.
job_dir (Path) – Path to the job directory.
- Return type:
- Raises:
ValueError – If the manifest contains no file entries.
- class impact_engine_evaluate.MethodReviewerRegistry[source]
Discover and instantiate registered method reviewers.
- classmethod register(name)[source]
Class decorator that registers a method reviewer under name.
- Parameters:
name (str) – Lookup key (typically the
model_typevalue from manifests).- Returns:
The original class, unmodified.
- Return type:
Callable
- classmethod create(name, **kwargs)[source]
Instantiate a registered method reviewer.
- class impact_engine_evaluate.KnowledgeBase[source]
Abstract base class for knowledge base implementations.
Subclass and implement
load()to provide custom knowledge base content from any source (filesystem, database, API, etc.).
- class impact_engine_evaluate.DirectoryKnowledgeBase(directory)[source]
Knowledge base backed by a directory of
.mdand.txtfiles.- Parameters:
directory (str | Path) – Path to a directory containing
.mdor.txtknowledge files.
- class impact_engine_evaluate.KnowledgeBaseRegistry[source]
Registry mapping names to
KnowledgeBaseinstances.- register(name, knowledge_base)[source]
Register a knowledge base under name.
- Parameters:
name (str) – Registry key used to look up this knowledge base.
knowledge_base (KnowledgeBase) – Knowledge base instance to register.
- Return type:
None
- class impact_engine_evaluate.Prompt[source]
Abstract base class for prompt template implementations.
Subclass and implement
load()to provide custom prompt content from any source (filesystem, database, generated dynamically, etc.).
- class impact_engine_evaluate.FilePrompt(path)[source]
Prompt backed by a YAML template file.
- Parameters:
path (str | Path) – Path to a YAML prompt template file.
- load()[source]
Load and return the
PromptSpecfrom the YAML file.- Return type:
- Raises:
FileNotFoundError – If the path does not exist.
- class impact_engine_evaluate.PromptRegistry[source]
Registry mapping names to
Promptinstances.
Scorer
Job Reader
Shared job directory reader: build scorer events from job artifacts.
- impact_engine_evaluate.job_reader.load_scorer_event(manifest, job_dir, overrides=None)[source]
Build a scorer event dict from a job directory’s
impact_results.json.- Parameters:
- Returns:
Flat dict with keys
initiative_id,model_type,ci_upper,effect_estimate,ci_lower,cost_to_scale, andsample_size.- Return type:
- Raises:
FileNotFoundError – If
impact_results.jsonis not found in the job directory.
Adapter
Configuration
Unified configuration for the review subsystem.
- class impact_engine_evaluate.config.BackendConfig(model='claude-sonnet-4-5-20250929', temperature=0.0, max_tokens=4096, extra=<factory>)[source]
Bases:
objectLLM backend configuration.
- Parameters:
- class impact_engine_evaluate.config.MethodConfig(prompt='', knowledge_base='')[source]
Bases:
objectPer-method prompt and knowledge base selection.
- Parameters:
- class impact_engine_evaluate.config.ReviewConfig(backend=<factory>, methods=<factory>)[source]
Bases:
objectTop-level configuration for the review subsystem.
- Parameters:
backend (BackendConfig) – LLM backend settings.
methods (dict[str, MethodConfig]) – Per-method prompt and knowledge base overrides, keyed by
model_type.
- __init__(backend=<factory>, methods=<factory>)
- Parameters:
backend (BackendConfig)
methods (dict[str, MethodConfig])
- Return type:
None
Review API
Public API: review a job directory.
- impact_engine_evaluate.review.api.compute_review(job_dir, *, config=None)[source]
Compute a review of a job directory without writing results.
Suitable for evaluation loops and batch processing where writing back to the job directory is unwanted.
Prompt and knowledge base are resolved in this order:
If
config.methods[model_type].promptis set, the named prompt is loaded from the prompt registry.Otherwise the reviewer’s default
prompt_template_dir()is used.
The same precedence applies to
knowledge_base.- Parameters:
job_dir (str | Path) – Path to the job directory containing
manifest.json.config (ReviewConfig | dict | str | None) – Backend and method configuration. A
ReviewConfig, a dict, a YAML file path, orNonefor defaults.
- Return type:
- Raises:
FileNotFoundError – If the manifest or prompt template is missing.
KeyError – If the manifest’s
model_typehas no registered method reviewer, or a configured prompt / knowledge base name is not registered.
- impact_engine_evaluate.review.api.review(job_dir, *, config=None)[source]
Review a job directory and write results back.
Calls
compute_review()then writesreview_result.jsonto the job directory.- Parameters:
job_dir (str | Path) – Path to the job directory containing
manifest.json.config (ReviewConfig | dict | str | None) – Backend and method configuration. A
ReviewConfig, a dict, a YAML file path, orNonefor defaults.
- Return type:
- Raises:
FileNotFoundError – If the manifest or prompt template is missing.
KeyError – If the manifest’s
model_typehas no registered method reviewer, or a configured prompt / knowledge base name is not registered.
Review Engine
ReviewEngine: orchestrates a single artifact review.
- class impact_engine_evaluate.review.engine.PromptBuilder[source]
Bases:
objectLoad prompt specs and knowledge, then render chat messages.
Encapsulates the Jinja2 template rendering and knowledge loading steps shared across all method reviewers. This is the shared entry layer inside the Evaluation Engine that runs before any LLM call.
- load_spec(path)[source]
Load a PromptSpec from a YAML file.
- Parameters:
path (Path) – Path to a YAML prompt template file.
- Return type:
- Raises:
FileNotFoundError – If path does not exist.
- class impact_engine_evaluate.review.engine.ResultsBuilder[source]
Bases:
objectParse structured LLM output into a ReviewResult.
Translates the raw Pydantic
ReviewResponsefrom LiteLLM into theReviewResultdataclass used downstream. This is the shared exit layer inside the Evaluation Engine that runs after every LLM call.- parse(artifact, spec, model, response)[source]
Parse a LiteLLM structured response into a ReviewResult.
- Parameters:
artifact (ArtifactPayload) – The artifact that was reviewed.
spec (PromptSpec) – Prompt spec used for the review.
model (str) – Model identifier that produced the response.
response (Any) – Raw LiteLLM completion response. Either
choices[0].message.parsed(OpenAI-style structured output) orchoices[0].message.content(JSON string, as returned by ollama and other backends) is accepted.
- Return type:
- class impact_engine_evaluate.review.engine.ReviewEngine(*, default_model='claude-sonnet-4-5-20250929', default_temperature=0.0, default_max_tokens=4096, litellm_extra=None)[source]
Bases:
objectExecute an artifact review via LiteLLM.
- Parameters:
- __init__(*, default_model='claude-sonnet-4-5-20250929', default_temperature=0.0, default_max_tokens=4096, litellm_extra=None)[source]
- classmethod from_config(config=None)[source]
Construct a ReviewEngine from a config dict or raw source.
- review(artifact, spec, knowledge_context='', *, model=None, temperature=None, max_tokens=None)[source]
Execute a review of the given artifact.
- Parameters:
artifact (ArtifactPayload) – The artifact to review.
spec (PromptSpec) – Prompt template specification.
knowledge_context (str) – Pre-loaded domain knowledge text.
model (str | None) – Model override for this call.
temperature (float | None) – Temperature override for this call.
max_tokens (int | None) – Max tokens override for this call.
- Return type:
- impact_engine_evaluate.review.engine.load_prompt_spec(path)[source]
Load a PromptSpec from a YAML file.
- Parameters:
path (Path) – Path to a YAML prompt template file.
- Return type:
Review Models
Data models for artifact review.
- class impact_engine_evaluate.review.models.DimensionResponse(*, name, score, justification)[source]
Bases:
BaseModelSingle dimension in a structured review response.
- model_config = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class impact_engine_evaluate.review.models.ReviewResponse(*, dimensions, overall)[source]
Bases:
BaseModelStructured response schema for LLM review output.
- Parameters:
dimensions (list[DimensionResponse])
overall (float)
- model_config = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class impact_engine_evaluate.review.models.ReviewDimension(name, score, justification)[source]
Bases:
objectA single scored dimension of an artifact review.
- Parameters:
- class impact_engine_evaluate.review.models.ReviewResult(initiative_id, prompt_name, prompt_version, backend_name, model, dimensions=<factory>, overall_score=0.0, raw_response='', timestamp='')[source]
Bases:
objectComplete result of an artifact review.
- Parameters:
initiative_id (str) – Identifier of the reviewed initiative.
prompt_name (str) – Name of the prompt template used.
prompt_version (str) – Version string of the prompt template.
backend_name (str) – Registered name of the LLM backend.
model (str) – Model identifier used for completion.
dimensions (list[ReviewDimension]) – Per-dimension scores and justifications.
overall_score (float) – Aggregated score across dimensions (mean).
raw_response (str) – Full LLM output retained for audit.
timestamp (str) – ISO-8601 timestamp of the review.
- __init__(initiative_id, prompt_name, prompt_version, backend_name, model, dimensions=<factory>, overall_score=0.0, raw_response='', timestamp='')
- class impact_engine_evaluate.review.models.ArtifactPayload(initiative_id, artifact_text, model_type='', sample_size=0, metadata=<factory>)[source]
Bases:
objectTyped input envelope for an artifact to review.
- Parameters:
- class impact_engine_evaluate.review.models.PromptSpec(name, version, description, dimensions=<factory>, system_template='', user_template='')[source]
Bases:
objectMetadata and template content for a review prompt.
- Parameters:
name (str) – Unique prompt identifier.
version (str) – Semver-style version string.
description (str) – Human-readable description.
dimensions (list[str]) – Names of scoring dimensions this prompt expects.
system_template (str) – Jinja2 template for the system message.
user_template (str) – Jinja2 template for the user message.
Manifest
Job directory manifest: load, validate, and update.
- class impact_engine_evaluate.review.manifest.FileEntry(path, format)[source]
Bases:
objectA single file reference within a manifest.
- Parameters:
- class impact_engine_evaluate.review.manifest.Manifest(model_type, created_at='', files=<factory>, initiative_id='', evaluate_strategy='review')[source]
Bases:
objectParsed manifest for a job directory.
- Parameters:
model_type (str) – Causal inference methodology label.
created_at (str) – ISO-8601 creation timestamp.
files (dict[str, FileEntry]) – Mapping of logical names to file entries.
initiative_id (str) – Initiative identifier. Defaults to the job directory name.
evaluate_strategy (str) – Evaluation strategy:
"review"(LLM review) or"score"(deterministic confidence). Defaults to"review".
- impact_engine_evaluate.review.manifest.load_manifest(job_dir)[source]
Load and validate a manifest from a job directory.
- Parameters:
job_dir (str | Path) – Path to the job directory containing
manifest.json.- Return type:
- Raises:
FileNotFoundError – If
manifest.jsondoes not exist.ValueError – If required fields are missing.
Method Reviewer Base
Abstract method reviewer and registry.
- class impact_engine_evaluate.review.methods.base.MethodReviewer[source]
Bases:
ABCBase class for methodology-specific artifact reviewers.
Each method reviewer bundles its own prompt template, knowledge base content, and artifact loading logic. The default
load_artifactreads all files listed in the manifest and attempts to extractsample_sizefrom the first JSON file. Subclasses may override if they need method-specific loading.- confidence_range
(lower, upper)bounds for deterministic confidence scoring.
- load_artifact(manifest, job_dir)[source]
Read artifact files per manifest and return a payload.
The default implementation reads every file entry in manifest, concatenates their contents, and extracts
sample_sizefrom the first JSON file that contains one. Subclasses may override for method-specific loading.- Parameters:
manifest (Manifest) – Parsed job manifest.
job_dir (Path) – Path to the job directory.
- Return type:
- Raises:
ValueError – If the manifest contains no file entries.
- class impact_engine_evaluate.review.methods.base.MethodReviewerRegistry[source]
Bases:
objectDiscover and instantiate registered method reviewers.
- classmethod register(name)[source]
Class decorator that registers a method reviewer under name.
- Parameters:
name (str) – Lookup key (typically the
model_typevalue from manifests).- Returns:
The original class, unmodified.
- Return type:
Callable
- classmethod create(name, **kwargs)[source]
Instantiate a registered method reviewer.