Home / Class/ Citation Class — langchain Architecture

Citation Class — langchain Architecture

Architecture documentation for the Citation class in content.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  87cfbdcb_a48e_eafc_d682_773f69f7d538["Citation"]
  c7f11daf_e104_efbe_7225_f1d6da8e8630["content.py"]
  87cfbdcb_a48e_eafc_d682_773f69f7d538 -->|defined in| c7f11daf_e104_efbe_7225_f1d6da8e8630

Relationship Graph

Source Code

libs/core/langchain_core/messages/content.py lines 126–181

class Citation(TypedDict):
    """Annotation for citing data from a document.

    !!! note

        `start`/`end` indices refer to the **response text**,
        not the source text. This means that the indices are relative to the model's
        response, not the original document (as specified in the `url`).

    !!! note "Factory function"

        `create_citation` may also be used as a factory to create a `Citation`.
        Benefits include:

        * Automatic ID generation (when not provided)
        * Required arguments strictly validated at creation time
    """

    type: Literal["citation"]
    """Type of the content block. Used for discrimination."""

    id: NotRequired[str]
    """Unique identifier for this content block.

    Either:

    - Generated by the provider
    - Generated by LangChain upon creation (`UUID4` prefixed with `'lc_'`))
    """

    url: NotRequired[str]
    """URL of the document source."""

    title: NotRequired[str]
    """Source document title.

    For example, the page title for a web page or the title of a paper.
    """

    start_index: NotRequired[int]
    """Start index of the **response text** (`TextContentBlock.text`)."""

    end_index: NotRequired[int]
    """End index of the **response text** (`TextContentBlock.text`)"""

    cited_text: NotRequired[str]
    """Excerpt of source text being cited."""

    # NOTE: not including spans for the raw document text (such as `text_start_index`
    # and `text_end_index`) as this is not currently supported by any provider. The
    # thinking is that the `cited_text` should be sufficient for most use cases, and it
    # is difficult to reliably extract spans from the raw document text across file
    # formats or encoding schemes.

    extras: NotRequired[dict[str, Any]]
    """Provider-specific metadata."""

Frequently Asked Questions

What is the Citation class?
Citation is a class in the langchain codebase, defined in libs/core/langchain_core/messages/content.py.
Where is Citation defined?
Citation is defined in libs/core/langchain_core/messages/content.py at line 126.

Analyze Your Own Codebase

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

Try Supermodel Free