Home / Function/ create_tagging_chain() — langchain Function Reference

create_tagging_chain() — langchain Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

libs/langchain/langchain_classic/chains/openai_functions/tagging.py lines 51–109

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

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

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

    ```python
    from typing_extensions import Annotated, TypedDict
    from langchain_anthropic import ChatAnthropic

    class Joke(TypedDict):
        \"\"\"Tagged joke.\"\"\"

        setup: Annotated[str, ..., "The setup of the joke"]
        punchline: Annotated[str, ..., "The punchline of 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-3-haiku-20240307", 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:
        schema: The 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.

    """
    function = _get_tagging_function(schema)
    prompt = prompt or ChatPromptTemplate.from_template(_TAGGING_TEMPLATE)
    output_parser = JsonOutputFunctionsParser()
    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() do?
create_tagging_chain() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/chains/openai_functions/tagging.py.
Where is create_tagging_chain() defined?
create_tagging_chain() is defined in libs/langchain/langchain_classic/chains/openai_functions/tagging.py at line 51.
What does create_tagging_chain() call?
create_tagging_chain() 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