Commit 7919d4f
Add citation support.
[Here](https://python.langchain.com/docs/integrations/chat/anthropic/#simple-example)
is an example using langchain_anthropic.
```py
from langchain_core.messages import HumanMessage, SystemMessage
from langchain_aws import ChatBedrockConverse
llm = ChatBedrockConverse(
model="eu.anthropic.claude-3-7-sonnet-20250219-v1:0",
max_tokens=1000,
temperature=0.1,
)
response = llm.invoke(
input=[
HumanMessage(
content=[
{
"type": "document",
"document": {
"format": "txt",
"source": {
"text": "The grass is green. The sky is blue."
},
"name": "My Document",
'context': 'This is a trustworthy document.',
"citations": {"enabled": True},
},
},
{"type": "text", "text": "What color is the grass and sky?"},
]
),
],
)
response.content
```
This results in a Validation
```
ValueError: Unexpected content block type in content. Expected to have one of 'text', 'tool_use', 'image', 'video, 'document', 'tool_result','json', 'guard_content', 'reasoning_content', or 'citations_content' keys. Received:
{'citations_content': {'content': [{'text': 'The grass is green.'}], 'citations': [{'title': 'My Document', 'source_content': [{'text': 'The grass is green. '}], 'location': {'document_char': {'document_index': 0, 'start': 0, 'end': 20}}}]}}
```
with the incoming changes the `citations` list is preserved as I believe
langchain_anthropic
[does](https://github.com/langchain-ai/langchain/blob/ad44f0688b1cc0809e526b9bf1ff68127aee8d48/libs/partners/anthropic/langchain_anthropic/chat_models.py#L2150)
---------
Co-authored-by: Iñigo Gaston <[email protected]>
Co-authored-by: Michael Chin <[email protected]>
1 parent d97e1b3 commit 7919d4f
1 file changed
+14
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1378 | 1378 | | |
1379 | 1379 | | |
1380 | 1380 | | |
| 1381 | + | |
| 1382 | + | |
| 1383 | + | |
| 1384 | + | |
| 1385 | + | |
| 1386 | + | |
| 1387 | + | |
| 1388 | + | |
| 1389 | + | |
| 1390 | + | |
| 1391 | + | |
| 1392 | + | |
1381 | 1393 | | |
1382 | 1394 | | |
1383 | 1395 | | |
1384 | 1396 | | |
1385 | 1397 | | |
1386 | | - | |
1387 | | - | |
| 1398 | + | |
| 1399 | + | |
1388 | 1400 | | |
1389 | 1401 | | |
1390 | 1402 | | |
| |||
0 commit comments