create_extraction_chain_pydantic() — langchain Function Reference
Architecture documentation for the create_extraction_chain_pydantic() function in extraction.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD db895caf_3acd_7ed6_a019_ca0e621612f9["create_extraction_chain_pydantic()"] f3ae89de_9c39_fe1b_3ede_79ea9e0ed4fe["extraction.py"] db895caf_3acd_7ed6_a019_ca0e621612f9 -->|defined in| f3ae89de_9c39_fe1b_3ede_79ea9e0ed4fe d96ba5e6_9d3c_8107_e3e7_4c1c7394f868["_get_extraction_function()"] db895caf_3acd_7ed6_a019_ca0e621612f9 -->|calls| d96ba5e6_9d3c_8107_e3e7_4c1c7394f868 style db895caf_3acd_7ed6_a019_ca0e621612f9 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/langchain/langchain_classic/chains/openai_functions/extraction.py lines 145–190
def create_extraction_chain_pydantic(
pydantic_schema: Any,
llm: BaseLanguageModel,
prompt: BasePromptTemplate | None = None,
verbose: bool = False, # noqa: FBT001,FBT002
) -> Chain:
"""Creates a chain that extracts information from a passage using Pydantic schema.
Args:
pydantic_schema: The Pydantic schema of the entities to extract.
llm: The language model to use.
prompt: The prompt to use for extraction.
verbose: Whether to run in verbose mode. In verbose mode, some intermediate
logs will be printed to the console.
Returns:
Chain that can be used to extract information from a passage.
"""
class PydanticSchema(BaseModel):
info: list[pydantic_schema]
if hasattr(pydantic_schema, "model_json_schema"):
openai_schema = pydantic_schema.model_json_schema()
else:
openai_schema = pydantic_schema.schema()
openai_schema = _resolve_schema_references(
openai_schema,
openai_schema.get("definitions", {}),
)
function = _get_extraction_function(openai_schema)
extraction_prompt = prompt or ChatPromptTemplate.from_template(_EXTRACTION_TEMPLATE)
output_parser = PydanticAttrOutputFunctionsParser(
pydantic_schema=PydanticSchema,
attr_name="info",
)
llm_kwargs = get_llm_kwargs(function)
return LLMChain(
llm=llm,
prompt=extraction_prompt,
llm_kwargs=llm_kwargs,
output_parser=output_parser,
verbose=verbose,
)
Domain
Subdomains
Source
Frequently Asked Questions
What does create_extraction_chain_pydantic() do?
create_extraction_chain_pydantic() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/chains/openai_functions/extraction.py.
Where is create_extraction_chain_pydantic() defined?
create_extraction_chain_pydantic() is defined in libs/langchain/langchain_classic/chains/openai_functions/extraction.py at line 145.
What does create_extraction_chain_pydantic() call?
create_extraction_chain_pydantic() calls 1 function(s): _get_extraction_function.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free