dllmforge.IE_agent_schema_generator

Schema Generator module for automatically generating Pydantic models based on user descriptions and example documents using LLM.

Classes

PythonCodeOutputParser(*args[, name])

Parse Python code from LLM responses that may contain markdown.

SchemaGenerator([config, llm_api, ...])

Class for generating Pydantic schemas using LLM

class dllmforge.IE_agent_schema_generator.PythonCodeOutputParser(*args: Any, name: str | None = None)[source]

Parse Python code from LLM responses that may contain markdown.

parse(text: str) str[source]

Parse the output of an LLM call to extract Python code.

get_format_instructions() str[source]

Instructions on how the LLM output should be formatted.

model_config: ClassVar[ConfigDict] = {'extra': 'ignore', 'protected_namespaces': ()}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class dllmforge.IE_agent_schema_generator.SchemaGenerator(config: SchemaConfig | None = None, llm_api: LangchainAPI | None = None, task_description: str | None = None, example_doc: str | None = None, user_schema_path: Path | None = None, output_path: str | Path | None = None)[source]

Class for generating Pydantic schemas using LLM

This class supports two usage modes:

  1. CONFIG MODE: Pass a SchemaConfig object ```python config = SchemaConfig(

    task_description=”Extract person info”, output_path=”schema.py”

    ) generator = SchemaGenerator(config=config) ```

  2. DIRECT MODE: Pass arguments directly (no config object) ```python generator = SchemaGenerator(

    task_description=”Extract person info”, output_path=”schema.py”

Both modes support all parameters: - task_description (REQUIRED in direct mode) - example_doc (optional: text or file path) - user_schema_path (optional: load existing schema) - output_path (optional: where to save generated schema) - llm_api (optional: custom LLM configuration)

Initialize the schema generator.

You can use either config (SchemaConfig), or pass the individual parameters directly.

Parameters:
  • config – Schema generation configuration (if provided, individual params are ignored)

  • llm_api – Optional pre-configured LangchainAPI instance

  • task_description – Description of the information extraction task (direct mode)

  • example_doc – Example document to help with schema generation (direct mode)

  • user_schema_path – Path to user-provided schema Python file (direct mode)

  • output_path – Path to save generated schema (direct mode)

__init__(config: SchemaConfig | None = None, llm_api: LangchainAPI | None = None, task_description: str | None = None, example_doc: str | None = None, user_schema_path: Path | None = None, output_path: str | Path | None = None)[source]

Initialize the schema generator.

You can use either config (SchemaConfig), or pass the individual parameters directly.

Parameters:
  • config – Schema generation configuration (if provided, individual params are ignored)

  • llm_api – Optional pre-configured LangchainAPI instance

  • task_description – Description of the information extraction task (direct mode)

  • example_doc – Example document to help with schema generation (direct mode)

  • user_schema_path – Path to user-provided schema Python file (direct mode)

  • output_path – Path to save generated schema (direct mode)

setup_parser()[source]

Setup the Pydantic output parser for structured verification results

create_schema_generation_prompt() ChatPromptTemplate[source]

Create prompt template for generating Pydantic schema

generate_schema() str[source]

Generate Pydantic schema based on task description and optional example document

save_schema(schema_code: str) None[source]

Save generated schema to a Python file