Implementation:Ucbepic Docetl MapOptimizer PromptGenerators
| Knowledge Sources | |
|---|---|
| Domains | Data_Processing, Optimization |
| Last Updated | 2026-02-08 00:00 GMT |
Overview
Concrete tool for generating validator, combiner, header extraction, schema transform, and improvement prompts for map operation optimization provided by DocETL.
Description
The PromptGenerator class is a component of the MapOptimizer subsystem responsible for synthesizing various prompts needed during the optimization process. It generates validator prompts that assess output quality and completeness, header extraction prompts that identify document structure for chunk processing, combine prompts that merge results from multiple chunks in map-reduce operations, schema transformation prompts that convert parallel map outputs into the target schema, missing-keys synthesis prompts for chain plans with incomplete coverage, and improved operation prompts based on assessment feedback. It also determines whether combine operations are associative (order-independent).
Usage
Use PromptGenerator when you need to create specialized prompts for the map optimization workflow. It is used internally by the MapOptimizer and PlanGenerator to generate validation criteria, chunk combination logic, header detection, schema transformation, and prompt improvement. It is relevant whenever the optimizer needs to assess output quality, combine chunked results, or transform intermediate outputs to match a target schema.
Code Reference
Source Location
- Repository: Ucbepic_Docetl
- File: docetl/optimizers/map_optimizer/prompt_generators.py
- Lines: 1-698
Signature
class PromptGenerator:
def __init__(
self,
runner,
llm_client: LLMClient,
console: Console,
config: dict[str, Any],
max_threads: int,
is_filter: bool = False,
) -> None: ...
def _generate_validator_prompt(
self,
op_config: dict[str, Any],
input_data: list[dict[str, Any]],
output_data: list[dict[str, Any]],
) -> str: ...
def _get_header_extraction_prompt(
self,
op_config: dict[str, Any],
input_data: list[dict[str, Any]],
split_key: str,
) -> tuple[str, dict[str, Any]]: ...
def _get_improved_prompt(
self,
op_config: dict[str, Any],
assessment: dict[str, Any],
input_data_sample: list[dict[str, Any]],
) -> list[dict[str, Any]]: ...
def _get_combine_prompt(
self,
op_config: dict[str, Any],
sample_output: list[dict[str, Any]],
) -> tuple[str, bool]: ...
def _edit_subprompt_to_reflect_metadata(
self,
subprompt: str,
metadata_schema: dict[str, Any],
sample_output: list[dict[str, Any]],
) -> str: ...
def _get_schema_transform_prompt(
self,
op_config: dict[str, Any],
parallel_output_schema: dict[str, Any],
target_schema: dict[str, Any],
sample_output: list[dict[str, Any]],
) -> str: ...
def _get_missing_keys_prompt(
self,
op_config: dict[str, Any],
missing_keys: set[str],
existing_keys: set[str],
) -> str: ...
Import
from docetl.optimizers.map_optimizer.prompt_generators import PromptGenerator
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| runner | Runner | Yes | The pipeline runner object |
| llm_client | LLMClient | Yes | Client for interacting with the language model |
| console | Console | Yes | Rich console object for output logging |
| config | dict[str, Any] | Yes | The pipeline configuration dictionary |
| max_threads | int | Yes | Maximum number of threads for parallel execution |
| is_filter | bool | No | Whether the operation is a filter operation (default: False) |
| op_config | dict[str, Any] | Yes | The operation configuration |
| input_data | list[dict[str, Any]] | Yes | Input data samples |
| output_data | list[dict[str, Any]] | Yes | Output data samples for validator prompt generation |
| split_key | str | Yes | Document split key for header extraction |
| sample_output | list[dict[str, Any]] | Yes | Sample outputs for combine prompt generation |
Outputs
| Name | Type | Description |
|---|---|---|
| validator_prompt | str | Custom prompt for assessing output quality |
| header_extraction_prompt | str | Jinja2 template prompt for extracting headers from document chunks |
| header_output_schema | dict[str, Any] | Output schema for extracted headers |
| combine_prompt | str | Jinja2 template for combining chunk results in map-reduce |
| is_associative | bool | Whether the combine operation is order-independent |
| transform_prompt | str | Prompt for transforming parallel output schema to target schema |
| synthesis_prompt | str | Prompt for generating missing output keys in chain plans |
| improved_ops | list[dict[str, Any]] | Operation configs with improved prompts |
Usage Examples
from docetl.optimizers.map_optimizer.prompt_generators import PromptGenerator
prompt_gen = PromptGenerator(
runner=pipeline_runner,
llm_client=llm_client,
console=console,
config=pipeline_config,
max_threads=4,
)
# Generate a validator prompt
validator_prompt = prompt_gen._generate_validator_prompt(
op_config=map_op_config,
input_data=input_samples,
output_data=output_samples,
)
print(f"Validator prompt: {validator_prompt}")
# Generate a combine prompt for chunk results
combine_prompt, is_associative = prompt_gen._get_combine_prompt(
op_config=map_op_config,
sample_output=chunk_outputs,
)
print(f"Combine is associative: {is_associative}")
# Generate header extraction prompt
header_prompt, header_schema = prompt_gen._get_header_extraction_prompt(
op_config=map_op_config,
input_data=input_samples,
split_key="document_text",
)