LangChain.Message.Citation (LangChain v0.6.0)

Copy Markdown View Source

Represents a citation linking a span of response text to a source.

All four major providers (Anthropic, OpenAI, Google, Perplexity) share the pattern of linking response text to sources. This struct normalizes those provider-specific formats into a common shape.

Fields

  • :cited_text - The actual text cited from the source (when available)
  • :source - A CitationSource identifying where the citation came from
  • :start_index - Character offset into the ContentPart's text where this citation starts
  • :end_index - Character offset where this citation ends
  • :confidence - Confidence score (0.0-1.0) when provided (e.g., Gemini)
  • :metadata - Provider-specific data for round-tripping. String keys for JSON serialization.

Summary

Functions

Filters citations by source type.

Returns all unique source URLs from a list of citations.

Types

t()

@type t() :: %LangChain.Message.Citation{
  cited_text: term(),
  confidence: term(),
  end_index: term(),
  metadata: term(),
  source: term(),
  start_index: term()
}

Functions

filter_by_source_type(citations, type)

@spec filter_by_source_type([t()], atom()) :: [t()]

Filters citations by source type.

new(attrs \\ %{})

@spec new(map()) :: {:ok, t()} | {:error, Ecto.Changeset.t()}

new!(attrs \\ %{})

@spec new!(map()) :: t() | no_return()

source_urls(citations)

@spec source_urls([t()]) :: [String.t()]

Returns all unique source URLs from a list of citations.