# 400 error from concatenated annotation fields during chunk aggregation (OpenAI + built-in file\_search)

**URL:** <https://forum.langchain.com/t/400-error-from-concatenated-annotation-fields-during-chunk-aggregation-openai-built-in-file-search/1767>\
**Category:** LangChain\
**Tags:** python-help\
**Created:** [October 7, 2025, 2:48pm UTC](https://forum.langchain.com/t/400-error-from-concatenated-annotation-fields-during-chunk-aggregation-openai-built-in-file-search/1767 "2025-10-07T14:48:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dnogueira](https://yyz1.discourse-cdn.com/flex007/user_avatar/forum.langchain.com/dnogueira/32/1079_2.png) [@dnogueira](https://forum.langchain.com/u/dnogueira)\
**Post date:** [October 7, 2025, 2:48pm UTC](https://forum.langchain.com/t/400-error-from-concatenated-annotation-fields-during-chunk-aggregation-openai-built-in-file-search/1767/1 "2025-10-07T14:48:03Z")

</div>

I’m hitting the following error while streaming with OpenAI using the built-in file\_search tool:

> Error code: 400 - {‘error’: {‘message’: “Invalid ‘input[3].content[0].annotations[0].file\_id’: string too long. Expected a string with maximum length 64, but got a string with length 135 instead”}}

What I see:

- The model sometimes returns identical annotation deltas (same annotation payload, same index) on the same content block.
- When LangChain aggregates these identical annotation deltas into an AIMessage, the two dicts are merged (matched by index) and their string fields are concatenated (e.g., file\_id, filename), producing invalid values and breaching provider limits (e.g., file\_id max 64 chars).

Setup (simplified from my app):

```python
from langchain.agents import create_agent
from langchain_openai import ChatOpenAI
from langgraph.checkpoint.memory import InMemorySaver

model = ChatOpenAI(model="gpt-4.1-mini")

agent = create_agent(
    model=model,
    tools=[{"type": "file_search", "vector_store_ids": ["vs_..."]}],
    checkpointer=InMemorySaver()
    # streaming with .astream(..., stream_mode="messages")
)

```

Observed chunks:

> content=[{‘type’: ‘text’, ‘annotations’: [{‘type’: ‘file\_citation’, ‘file\_id’: ‘file-CV8…’, ‘filename’: name\_of\_file.md’, ‘index’: 1724}], ‘index’: 1}] additional\_kwargs={} response\_metadata={‘model\_provider’: ‘openai’} id=‘lc\_run–9e7b058b…’

> content=[{‘type’: ‘text’, ‘annotations’: [{‘type’: ‘file\_citation’, ‘file\_id’: ‘file-CV8…’, ‘filename’: name\_of\_file.md’, ‘index’: 1724}], ‘index’: 1}] additional\_kwargs={} response\_metadata={‘model\_provider’: ‘openai’} id=‘lc\_run–9e7b058b…’

> content=[{‘type’: ‘text’, ‘annotations’: [{‘type’: ‘file\_citation’, ‘file\_id’: ‘file-CV8…’, ‘filename’: name\_of\_file.md’, ‘index’: 1724}], ‘index’: 1}] additional\_kwargs={} response\_metadata={‘model\_provider’: ‘openai’} id=‘lc\_run–9e7b058b…’

Minimal repro (mirrors what I’m seeing when two identical annotation deltas arrive with the same index):

```python
from langchain_core.messages.ai import AIMessageChunk, add_ai_message_chunks

def make_chunk(ann_index: int) -> AIMessageChunk:
    return AIMessageChunk(
        content=[{
            "type": "text",
            "annotations": [{
                "type": "file_citation",
                "file_id": "file-CV8...",
                "filename": "name_of_file.md",
                "index": ann_index,
            }],
            "index": 1,
        }],
        additional_kwargs={},
        response_metadata={"model_provider": "openai"},
        id="lc_run--example",
    )

a = make_chunk(1724)
b = make_chunk(1724) # identical annotation, same index
ab = add_ai_message_chunks(a, b)

# ab.content[0]["annotations"][0] now has concatenated strings:
# file_id == "file-...file-..."
# filename == "name_of_file.mdname_of_file.md"
# -> leads to length > 64 and the 400 error above, depending on the size of [name_of_file]

```

Question:

- Given this occurs specifically when OpenAI returns identical annotation deltas with the same index while using the built-in file\_search tool, should clients dedupe these, or should LangChain avoid concatenating string fields for annotation dicts?

Environment:

- langchain\>=1.0.0a10
- langchain-core\>=1.0.0a5
- langchain-openai\>=1.0.0a3

---

<div class="post-metadata">

**Author:** ![chester-lc](https://avatars.discourse-cdn.com/v4/letter/c/71c47a/32.png) [@chester-lc](https://forum.langchain.com/u/chester-lc)\
**Post date:** [October 8, 2025, 2:51pm UTC](https://forum.langchain.com/t/400-error-from-concatenated-annotation-fields-during-chunk-aggregation-openai-built-in-file-search/1767/2 "2025-10-08T14:51:46Z")

</div>

Thanks for reporting this, this is a bug. I’ve opened a PR and will release a fix.

> <https://github.com/langchain-ai/langchain/pull/33350>
>
> Collision with the \`"index"\` key, originally reported here: https://forum.langch…ain.com/t/400-error-from-concatenated-annotation-fields-during-chunk-aggregation-openai-built-in-file-search/1767
