Skip to content

SchemaGenerator

SchemaGenerator is the main entry point. It builds the LangGraph pipeline, wires up all agents, and exposes two methods for running the pipeline.

SchemaGeneratorPrompts

SchemaGeneratorPrompts(
    problem_definer_helper_prompt: str,
    problem_definer_prompt: str,
    schema_generator_prompt: str,
    schema_assessment_prompt: str,
    schema_refiner_prompt: str,
    query_generator_prompt: str,
    schema_data_assessment_prompt: str,
    schema_data_assessment_merger_prompt: str,
    schema_data_refiner_prompt: str,
    init_chat_generation_summarizer_prompt: str,
    init_chat_system_message_prompt: str,
    init_chat_first_message_prompt: str,
)

SchemaGenerator

SchemaGenerator(
    llm: BaseChatModel,
    retriever: DocumentRetriever,
    prompts: SchemaGeneratorPrompts,
    use_interrupt: bool = False,
    graph_compilation_kwargs: dict[str, Any] | None = None,
    recursion_limit: int = 100,
    max_refinement_rounds: int = 3,
    min_refinement_rounds: int = 2,
    max_data_refinement_rounds: int = 3,
    min_data_refinement_rounds: int = 2,
    data_assessment_top_k: int = 50,
    data_assessment_num_examples: int = 3,
    data_assessment_random_seed: int = 17,
    data_assessment_document_max_chars: int = 32000,
    max_retries: int = 3,
    skip_problem_definition: bool = False,
    skip_refinement: bool = False,
    skip_data_grounded: bool = False,
)

Multi-agent pipeline that turns a natural language problem statement into a typed extraction schema.

The pipeline runs five stages: problem definition (clarification dialogue + formalisation), query generation, criteria-based schema generation and refinement, data-grounded assessment and refinement against retrieved documents, and a summarisation + interactive chat phase. Any stage can be skipped via the skip_* flags.

Parameters:

Name Type Description Default
llm BaseChatModel

Language model used by all agents.

required
retriever DocumentRetriever

Document retriever for the data-grounded refinement stage. Any async callable matching (query, max_docs) -> list works; see DocumentRetriever.

required
prompts SchemaGeneratorPrompts

All agent prompt strings; see SchemaGeneratorPrompts.

required
max_refinement_rounds int

Upper bound on criteria-based refinement iterations. Default: 3.

3
min_refinement_rounds int

Minimum criteria-based refinement iterations. Default: 2.

2
max_data_refinement_rounds int

Upper bound on data-grounded refinement iterations. Default: 3.

3
min_data_refinement_rounds int

Minimum data-grounded refinement iterations. Default: 2.

2
data_assessment_top_k int

Documents retrieved per query for the assessment pool. Default: 50.

50
data_assessment_num_examples int

Documents sampled per assessment round. Default: 3.

3
data_assessment_random_seed int

Seed for reproducible document sampling. Default: 17.

17
data_assessment_document_max_chars int

Max characters of a retrieved document's string representation included in the assessment prompt, to avoid exceeding the model's context window on long documents. Default: 32_000.

32000
max_retries int

Retries for structured-output calls that fail with an openai.OpenAIError (rate limits, transient API errors, or a reasoning model exhausting its max_tokens budget before producing output). Default: 3.

3
use_interrupt bool

Use LangGraph interrupts instead of terminal input for human steps. Not yet fully implemented; raises NotImplementedError if set. Default: False.

False
graph_compilation_kwargs dict[str, Any] | None

Extra kwargs forwarded to StateGraph.compile.

None
recursion_limit int

Maximum LangGraph execution depth. Default: 100.

100
skip_problem_definition bool

Skip clarification dialogue; use raw user input as problem definition. Default: False.

False
skip_refinement bool

Skip the criteria-based assessment/refinement loop. Default: False.

False
skip_data_grounded bool

Skip data-grounded assessment and refinement. Default: False.

False

stream_graph_updates

stream_graph_updates(
    user_input: str,
    current_schema: SchemaFields | None = None,
    verbosity: str = "all",
) -> None

Run the pipeline end-to-end, logging progress as it goes.

Parameters:

Name Type Description Default
user_input str

Natural language description of the desired extraction schema.

required
current_schema SchemaFields | None

Existing schema to refine, if any.

None
verbosity str

One of "minimal", "all", "debug". "minimal" only logs the problem-definition helper dialogue and the final conversation, showing a progress bar for every intermediate step. "all" logs every agent's output at INFO level. "debug" behaves like "all" but relies on a DEBUG-level sink being configured, surfacing prompts and token usage. Default: "all".

'all'