Home / Function/ create_tagging_chain_pydantic() — langchain Function Reference

create_tagging_chain_pydantic() — langchain Function Reference

Architecture documentation for the create_tagging_chain_pydantic() function in tagging.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  45f789fd_fb10_099c_864a_38a22ba09902["create_tagging_chain_pydantic()"]
  d7a84d7c_0dad_2b82_1285_762f1da3e11b["tagging.py"]
  45f789fd_fb10_099c_864a_38a22ba09902 -->|defined in| d7a84d7c_0dad_2b82_1285_762f1da3e11b
  57233e9a_5d8f_002b_971b_6f6d23e0d35a["_get_tagging_function()"]
  45f789fd_fb10_099c_864a_38a22ba09902 -->|calls| 57233e9a_5d8f_002b_971b_6f6d23e0d35a
  style 45f789fd_fb10_099c_864a_38a22ba09902 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/langchain_classic/chains/openai_functions/tagging.py lines 127–189

def create_tagging_chain_pydantic(
    pydantic_schema: Any,
    llm: BaseLanguageModel,
    prompt: ChatPromptTemplate | None = None,
    **kwargs: Any,
) -> Chain:
    """Create tagging chain from Pydantic schema.

    Create a chain that extracts information from a passage
    based on a Pydantic schema.

    This function is deprecated. Please use `with_structured_output` instead.
    See example usage below:

    ```python
    from pydantic import BaseModel, Field
    from langchain_anthropic import ChatAnthropic


    class Joke(BaseModel):
        setup: str = Field(description="The setup of the joke")
        punchline: str = Field(description="The punchline to the joke")


    # Or any other chat model that supports tools.
    # Please reference to the documentation of structured_output
    # to see an up to date list of which models support
    # with_structured_output.
    model = ChatAnthropic(model="claude-opus-4-1-20250805", temperature=0)
    structured_model = model.with_structured_output(Joke)
    structured_model.invoke(
        "Why did the cat cross the road? To get to the other "
        "side... and then lay down in the middle of it!"
    )
    ```

    Read more here: https://docs.langchain.com/oss/python/langchain/models#structured-outputs

    Args:
        pydantic_schema: The Pydantic schema of the entities to extract.
        llm: The language model to use.
        prompt: The prompt template to use for the chain.
        kwargs: Additional keyword arguments to pass to the chain.

    Returns:
        Chain (`LLMChain`) that can be used to extract information from a passage.

    """
    if hasattr(pydantic_schema, "model_json_schema"):
        openai_schema = pydantic_schema.model_json_schema()
    else:
        openai_schema = pydantic_schema.schema()
    function = _get_tagging_function(openai_schema)
    prompt = prompt or ChatPromptTemplate.from_template(_TAGGING_TEMPLATE)
    output_parser = PydanticOutputFunctionsParser(pydantic_schema=pydantic_schema)
    llm_kwargs = get_llm_kwargs(function)
    return LLMChain(
        llm=llm,
        prompt=prompt,
        llm_kwargs=llm_kwargs,
        output_parser=output_parser,
        **kwargs,
    )

Subdomains

Frequently Asked Questions

What does create_tagging_chain_pydantic() do?
create_tagging_chain_pydantic() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/chains/openai_functions/tagging.py.
Where is create_tagging_chain_pydantic() defined?
create_tagging_chain_pydantic() is defined in libs/langchain/langchain_classic/chains/openai_functions/tagging.py at line 127.
What does create_tagging_chain_pydantic() call?
create_tagging_chain_pydantic() calls 1 function(s): _get_tagging_function.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free