"TypeError: string indices must be integers" in line: "for output in app.stream(inputs):" #138

Closed
opened 2026-02-20 17:28:43 -05:00 by yindo · 3 comments
Owner

Originally created by @pranavkr29 on GitHub (Jul 8, 2024).

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangGraph/LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangGraph/LangChain rather than my code.
  • I am sure this is better as an issue rather than a GitHub discussion, since this is a LangGraph bug and not a design question.

Example Code

In the final web search example from the local crag notebook, 

from pprint import pprint

# Compile
app = workflow.compile()
inputs = {"question": "Who won the 2024 UK general elections?"}
for output in app.stream(inputs):
    for key, value in output.items():
        pprint(f"Finished running: {key}:")
pprint(value["generation"])

Error Message and Stack Trace (if applicable)

TypeError                                 Traceback (most recent call last)
Cell In[24], line 6
      4 app = workflow.compile()
      5 inputs = {"question": "Who won the 2024 UK general elections?"}
----> 6 for output in app.stream(inputs):
      7     for key, value in output.items():
      8         pprint(f"Finished running: {key}:")

File ~/GitHub/rag_cookbook/.rag_env/lib/python3.10/site-packages/langgraph/pregel/__init__.py:986, in Pregel.stream(self, input, config, stream_mode, output_keys, input_keys, interrupt_before, interrupt_after, debug)
    983         del fut, task
    985 # panic on failure or timeout
--> 986 _panic_or_proceed(done, inflight, step)
    987 # don't keep futures around in memory longer than needed
    988 del done, inflight, futures

File ~/GitHub/rag_cookbook/.rag_env/lib/python3.10/site-packages/langgraph/pregel/__init__.py:1540, in _panic_or_proceed(done, inflight, step)
   1538             inflight.pop().cancel()
   1539         # raise the exception
-> 1540         raise exc
   1542 if inflight:
   1543     # if we got here means we timed out
   1544     while inflight:
   1545         # cancel all pending tasks
...
--> 124 web_results = "\n".join([d["content"] for d in docs])
    125 web_results = Document(page_content=web_results)
    126 if documents is not None:

TypeError: string indices must be integers

Description

the previous index search example works, but the web search one fails. Could it be because i've provided a generic value to the API KEYS ?

System Info

Pip list of relevant libraries are as follows:
Python 3.10.12

langchain==0.2.5
langchain-community==0.2.5
langchain-core==0.2.9
langchain-nomic==0.1.2
langchain-text-splitters==0.2.1
langchainhub==0.1.20
ollama==0.2.1

Originally created by @pranavkr29 on GitHub (Jul 8, 2024). ### Checked other resources - [X] I added a very descriptive title to this issue. - [X] I searched the [LangGraph](https://langchain-ai.github.io/langgraph/)/LangChain documentation with the integrated search. - [X] I used the GitHub search to find a similar question and didn't find it. - [X] I am sure that this is a bug in LangGraph/LangChain rather than my code. - [X] I am sure this is better as an issue [rather than a GitHub discussion](https://github.com/langchain-ai/langgraph/discussions/new/choose), since this is a LangGraph bug and not a design question. ### Example Code ```python In the final web search example from the local crag notebook, from pprint import pprint # Compile app = workflow.compile() inputs = {"question": "Who won the 2024 UK general elections?"} for output in app.stream(inputs): for key, value in output.items(): pprint(f"Finished running: {key}:") pprint(value["generation"]) ``` ### Error Message and Stack Trace (if applicable) ```shell TypeError Traceback (most recent call last) Cell In[24], line 6 4 app = workflow.compile() 5 inputs = {"question": "Who won the 2024 UK general elections?"} ----> 6 for output in app.stream(inputs): 7 for key, value in output.items(): 8 pprint(f"Finished running: {key}:") File ~/GitHub/rag_cookbook/.rag_env/lib/python3.10/site-packages/langgraph/pregel/__init__.py:986, in Pregel.stream(self, input, config, stream_mode, output_keys, input_keys, interrupt_before, interrupt_after, debug) 983 del fut, task 985 # panic on failure or timeout --> 986 _panic_or_proceed(done, inflight, step) 987 # don't keep futures around in memory longer than needed 988 del done, inflight, futures File ~/GitHub/rag_cookbook/.rag_env/lib/python3.10/site-packages/langgraph/pregel/__init__.py:1540, in _panic_or_proceed(done, inflight, step) 1538 inflight.pop().cancel() 1539 # raise the exception -> 1540 raise exc 1542 if inflight: 1543 # if we got here means we timed out 1544 while inflight: 1545 # cancel all pending tasks ... --> 124 web_results = "\n".join([d["content"] for d in docs]) 125 web_results = Document(page_content=web_results) 126 if documents is not None: TypeError: string indices must be integers ``` ### Description the previous index search example works, but the web search one fails. Could it be because i've provided a generic value to the API KEYS ? ### System Info Pip list of relevant libraries are as follows: Python 3.10.12 langchain==0.2.5 langchain-community==0.2.5 langchain-core==0.2.9 langchain-nomic==0.1.2 langchain-text-splitters==0.2.1 langchainhub==0.1.20 ollama==0.2.1
yindo closed this issue 2026-02-20 17:28:44 -05:00
Author
Owner

@vbarda commented on GitHub (Jul 8, 2024):

@pranavkr29 what do you mean by "generic" value? for Tavily Search you would need to provide a working API key that you can get for free here https://tavily.com/

@vbarda commented on GitHub (Jul 8, 2024): @pranavkr29 what do you mean by "generic" value? for Tavily Search you would need to provide a working API key that you can get for free here https://tavily.com/
Author
Owner

@pranavkr29 commented on GitHub (Jul 8, 2024):

That fixed it. Thanks. Feel a little stupid, but that's normal

@pranavkr29 commented on GitHub (Jul 8, 2024): That fixed it. Thanks. Feel a little stupid, but that's normal
Author
Owner

@vbarda commented on GitHub (Jul 8, 2024):

That fixed it. Thanks. Feel a little stupid, but that's normal

No such thing! :) Glad I could help!

@vbarda commented on GitHub (Jul 8, 2024): > That fixed it. Thanks. Feel a little stupid, but that's normal No such thing! :) Glad I could help!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#138