Home / Function/ create_citation() — langchain Function Reference

create_citation() — langchain Function Reference

Architecture documentation for the create_citation() function in content.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  bad8751c_e256_33dc_c095_548ca01d0405["create_citation()"]
  c7f11daf_e104_efbe_7225_f1d6da8e8630["content.py"]
  bad8751c_e256_33dc_c095_548ca01d0405 -->|defined in| c7f11daf_e104_efbe_7225_f1d6da8e8630
  style bad8751c_e256_33dc_c095_548ca01d0405 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/langchain_core/messages/content.py lines 1404–1451

def create_citation(
    *,
    url: str | None = None,
    title: str | None = None,
    start_index: int | None = None,
    end_index: int | None = None,
    cited_text: str | None = None,
    id: str | None = None,
    **kwargs: Any,
) -> Citation:
    """Create a `Citation`.

    Args:
        url: URL of the document source.
        title: Source document title.
        start_index: Start index in the response text where citation applies.
        end_index: End index in the response text where citation applies.
        cited_text: Excerpt of source text being cited.
        id: Content block identifier.

            Generated automatically if not provided.

    Returns:
        A properly formatted `Citation`.

    !!! note

        The `id` is generated automatically if not provided, using a UUID4 format
        prefixed with `'lc_'` to indicate it is a LangChain-generated ID.
    """
    block = Citation(type="citation", id=ensure_id(id))

    if url is not None:
        block["url"] = url
    if title is not None:
        block["title"] = title
    if start_index is not None:
        block["start_index"] = start_index
    if end_index is not None:
        block["end_index"] = end_index
    if cited_text is not None:
        block["cited_text"] = cited_text

    extras = {k: v for k, v in kwargs.items() if v is not None}
    if extras:
        block["extras"] = extras

    return block

Domain

Subdomains

Frequently Asked Questions

What does create_citation() do?
create_citation() is a function in the langchain codebase, defined in libs/core/langchain_core/messages/content.py.
Where is create_citation() defined?
create_citation() is defined in libs/core/langchain_core/messages/content.py at line 1404.

Analyze Your Own Codebase

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

Try Supermodel Free