langchain · difficulty ◆◆◆
Citation Metadata in langchain-mistralai: Trace RAG Answers
Grounded answers you can inspect and trust
Your Mistral RAG answers were untraceable, hiding bad retrieval and hallucinations.
$ export MISTRAL_API_KEY=your-key-hereWhat it does
The MistralAI integration surfaces citation metadata from chat responses. When the model returns document citations, LangChain exposes them on the AIMessage via additional_kwargs["citations"] as structured, inspectable metadata.
Why it matters
Knowing which source chunks generated an answer is critical for traceability, hallucination detection, and debugging retrieval quality. Before this change the citation data was opaque inside LangChain; now it is first-class and filterable.
Example
$ Invoke a Mistral model and read citation metadata off the AIMessage.<class 'langchain_core.messages.ai.AIMessage'>
Citations returned: 2
[0] {"text": "The EU AI Act classifies AI systems...", "source_id": "doc_001"}
[1] {"text": "High-risk AI systems must undergo...", "source_id": "doc_042"}
Finish reason: stopThe exact schema is an array of objects with at minimum a source_id and cited text span.
Common flags
- ChatMistralAI.invoke()
- Returns an AIMessage with citation metadata
- AIMessage.additional_kwargs
- Dict holding non-standard LLM response fields
- MistralAIEmbeddings.embed_query()
- Embed text for retrieval, pair with citations
- langchain-core 1.4.7
- Added package version tracking to tracing metadata
History
Origin
Mistral returned citation spans in its raw API response, but LangChain kept them opaque before 1.1.6.
The fix
PR #37008 promoted citations to first-class metadata, enabling inspection and filtering like any message attribute.
Fun facts
Pros & cons
pros
- + Traceability in production RAG
- + First-class, filterable metadata
- + Enables hallucination detection
cons
- − Citation structure is provider-specific
- − Requires retrieved context to trigger
Takeaways
- 1Inspect additional_kwargs for citations
- 2Flag claims without citations
- 3Use source_id to fetch original text