load_summarize_chain ValidationError, str type expected
Labels: name: area: doc loader, name: auto:bug, name: area: models

### System Info

langchain 0.0.275
Ubuntu 20.04.6 LTS
llama-2-7b-chat.ggmlv3.q4_0.bin
llama-cpp-python 0.1.78


I am getting a validation error when trying to use the document summary chain. It is giving an error "str type expected". I am passing Document objects to the model. I have checked the type of all page contents and they are indeed strings.

**Error**
```bash
---------------------------------------------------------------------------
ValidationError                           Traceback (most recent call last)
[/home/waleedalfaris/localGPT/notebooks/doc_summary.ipynb](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a224c4c4d227d.vscode-resource.vscode-cdn.net/home/waleedalfaris/localGPT/notebooks/doc_summary.ipynb) Cell 9 line 5
      [3](vscode-notebook-cell://ssh-remote%2B7b22686f73744e616d65223a224c4c4d227d/home/waleedalfaris/localGPT/notebooks/doc_summary.ipynb#X34sdnNjb2RlLXJlbW90ZQ%3D%3D?line=2) docs = loader.load_and_split()
      [4](vscode-notebook-cell://ssh-remote%2B7b22686f73744e616d65223a224c4c4d227d/home/waleedalfaris/localGPT/notebooks/doc_summary.ipynb#X34sdnNjb2RlLXJlbW90ZQ%3D%3D?line=3) chain = load_summarize_chain(llm, chain_type='map_reduce')
----> [5](vscode-notebook-cell://ssh-remote%2B7b22686f73744e616d65223a224c4c4d227d/home/waleedalfaris/localGPT/notebooks/doc_summary.ipynb#X34sdnNjb2RlLXJlbW90ZQ%3D%3D?line=4) summary = chain.run(docs[:1])
      [6](vscode-notebook-cell://ssh-remote%2B7b22686f73744e616d65223a224c4c4d227d/home/waleedalfaris/localGPT/notebooks/doc_summary.ipynb#X34sdnNjb2RlLXJlbW90ZQ%3D%3D?line=5) print(summary)

File [~/localGPT/venv/lib/python3.10/site-packages/langchain/chains/base.py:475](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a224c4c4d227d.vscode-resource.vscode-cdn.net/home/waleedalfaris/localGPT/notebooks/~/localGPT/venv/lib/python3.10/site-packages/langchain/chains/base.py:475), in Chain.run(self, callbacks, tags, metadata, *args, **kwargs)
    473     if len(args) != 1:
    474         raise ValueError("`run` supports only one positional argument.")
--> 475     return self(args[0], callbacks=callbacks, tags=tags, metadata=metadata)[
    476         _output_key
    477     ]
    479 if kwargs and not args:
    480     return self(kwargs, callbacks=callbacks, tags=tags, metadata=metadata)[
    481         _output_key
    482     ]

File [~/localGPT/venv/lib/python3.10/site-packages/langchain/chains/base.py:282](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a224c4c4d227d.vscode-resource.vscode-cdn.net/home/waleedalfaris/localGPT/notebooks/~/localGPT/venv/lib/python3.10/site-packages/langchain/chains/base.py:282), in Chain.__call__(self, inputs, return_only_outputs, callbacks, tags, metadata, include_run_info)
    280 except (KeyboardInterrupt, Exception) as e:
    281     run_manager.on_chain_error(e)
--> 282     raise e
    283 run_manager.on_chain_end(outputs)
    284 final_outputs: Dict[str, Any] = self.prep_outputs(
    285     inputs, outputs, return_only_outputs
    286 )

File [~/localGPT/venv/lib/python3.10/site-packages/langchain/chains/base.py:276](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a224c4c4d227d.vscode-resource.vscode-cdn.net/home/waleedalfaris/localGPT/notebooks/~/localGPT/venv/lib/python3.10/site-packages/langchain/chains/base.py:276), in Chain.__call__(self, inputs, return_only_outputs, callbacks, tags, metadata, include_run_info)
    270 run_manager = callback_manager.on_chain_start(
    271     dumpd(self),
    272     inputs,
    273 )
    274 try:
    275     outputs = (
--> 276         self._call(inputs, run_manager=run_manager)
    277         if new_arg_supported
    278         else self._call(inputs)
    279     )
    280 except (KeyboardInterrupt, Exception) as e:
    281     run_manager.on_chain_error(e)

File [~/localGPT/venv/lib/python3.10/site-packages/langchain/chains/combine_documents/base.py:105](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a224c4c4d227d.vscode-resource.vscode-cdn.net/home/waleedalfaris/localGPT/notebooks/~/localGPT/venv/lib/python3.10/site-packages/langchain/chains/combine_documents/base.py:105), in BaseCombineDocumentsChain._call(self, inputs, run_manager)
    103 # Other keys are assumed to be needed for LLM prediction
    104 other_keys = {k: v for k, v in inputs.items() if k != self.input_key}
--> 105 output, extra_return_dict = self.combine_docs(
    106     docs, callbacks=_run_manager.get_child(), **other_keys
    107 )
    108 extra_return_dict[self.output_key] = output
    109 return extra_return_dict

File [~/localGPT/venv/lib/python3.10/site-packages/langchain/chains/combine_documents/map_reduce.py:209](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a224c4c4d227d.vscode-resource.vscode-cdn.net/home/waleedalfaris/localGPT/notebooks/~/localGPT/venv/lib/python3.10/site-packages/langchain/chains/combine_documents/map_reduce.py:209), in MapReduceDocumentsChain.combine_docs(self, docs, token_max, callbacks, **kwargs)
    197 def combine_docs(
    198     self,
    199     docs: List[Document],
   (...)
    202     **kwargs: Any,
    203 ) -> Tuple[str, dict]:
    204     """Combine documents in a map reduce manner.
    205 
    206     Combine by mapping first chain over all documents, then reducing the results.
    207     This reducing can be done recursively if needed (if there are many documents).
    208     """
--> 209     map_results = self.llm_chain.apply(
    210         # FYI - this is parallelized and so it is fast.
    211         [{self.document_variable_name: d.page_content, **kwargs} for d in docs],
    212         callbacks=callbacks,
    213     )
    214     question_result_key = self.llm_chain.output_key
    215     result_docs = [
    216         Document(page_content=r[question_result_key], metadata=docs[i].metadata)
    217         # This uses metadata from the docs, and the textual results from `results`
    218         for i, r in enumerate(map_results)
    219     ]

File [~/localGPT/venv/lib/python3.10/site-packages/langchain/chains/llm.py:189](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a224c4c4d227d.vscode-resource.vscode-cdn.net/home/waleedalfaris/localGPT/notebooks/~/localGPT/venv/lib/python3.10/site-packages/langchain/chains/llm.py:189), in LLMChain.apply(self, input_list, callbacks)
    187 except (KeyboardInterrupt, Exception) as e:
    188     run_manager.on_chain_error(e)
--> 189     raise e
    190 outputs = self.create_outputs(response)
    191 run_manager.on_chain_end({"outputs": outputs})

File [~/localGPT/venv/lib/python3.10/site-packages/langchain/chains/llm.py:186](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a224c4c4d227d.vscode-resource.vscode-cdn.net/home/waleedalfaris/localGPT/notebooks/~/localGPT/venv/lib/python3.10/site-packages/langchain/chains/llm.py:186), in LLMChain.apply(self, input_list, callbacks)
    181 run_manager = callback_manager.on_chain_start(
    182     dumpd(self),
    183     {"input_list": input_list},
    184 )
    185 try:
--> 186     response = self.generate(input_list, run_manager=run_manager)
    187 except (KeyboardInterrupt, Exception) as e:
    188     run_manager.on_chain_error(e)

File [~/localGPT/venv/lib/python3.10/site-packages/langchain/chains/llm.py:101](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a224c4c4d227d.vscode-resource.vscode-cdn.net/home/waleedalfaris/localGPT/notebooks/~/localGPT/venv/lib/python3.10/site-packages/langchain/chains/llm.py:101), in LLMChain.generate(self, input_list, run_manager)
     99 """Generate LLM result from inputs."""
    100 prompts, stop = self.prep_prompts(input_list, run_manager=run_manager)
--> 101 return self.llm.generate_prompt(
    102     prompts,
    103     stop,
    104     callbacks=run_manager.get_child() if run_manager else None,
    105     **self.llm_kwargs,
    106 )

File [~/localGPT/venv/lib/python3.10/site-packages/langchain/llms/base.py:467](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a224c4c4d227d.vscode-resource.vscode-cdn.net/home/waleedalfaris/localGPT/notebooks/~/localGPT/venv/lib/python3.10/site-packages/langchain/llms/base.py:467), in BaseLLM.generate_prompt(self, prompts, stop, callbacks, **kwargs)
    459 def generate_prompt(
    460     self,
    461     prompts: List[PromptValue],
   (...)
    464     **kwargs: Any,
    465 ) -> LLMResult:
    466     prompt_strings = [p.to_string() for p in prompts]
--> 467     return self.generate(prompt_strings, stop=stop, callbacks=callbacks, **kwargs)

File [~/localGPT/venv/lib/python3.10/site-packages/langchain/llms/base.py:602](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a224c4c4d227d.vscode-resource.vscode-cdn.net/home/waleedalfaris/localGPT/notebooks/~/localGPT/venv/lib/python3.10/site-packages/langchain/llms/base.py:602), in BaseLLM.generate(self, prompts, stop, callbacks, tags, metadata, **kwargs)
    593         raise ValueError(
    594             "Asked to cache, but no cache found at `langchain.cache`."
    595         )
    596     run_managers = [
    597         callback_manager.on_llm_start(
    598             dumpd(self), [prompt], invocation_params=params, options=options
    599         )[0]
    600         for callback_manager, prompt in zip(callback_managers, prompts)
    601     ]
--> 602     output = self._generate_helper(
    603         prompts, stop, run_managers, bool(new_arg_supported), **kwargs
    604     )
    605     return output
    606 if len(missing_prompts) > 0:

File [~/localGPT/venv/lib/python3.10/site-packages/langchain/llms/base.py:504](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a224c4c4d227d.vscode-resource.vscode-cdn.net/home/waleedalfaris/localGPT/notebooks/~/localGPT/venv/lib/python3.10/site-packages/langchain/llms/base.py:504), in BaseLLM._generate_helper(self, prompts, stop, run_managers, new_arg_supported, **kwargs)
    502     for run_manager in run_managers:
    503         run_manager.on_llm_error(e)
--> 504     raise e
    505 flattened_outputs = output.flatten()
    506 for manager, flattened_output in zip(run_managers, flattened_outputs):

File [~/localGPT/venv/lib/python3.10/site-packages/langchain/llms/base.py:491](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a224c4c4d227d.vscode-resource.vscode-cdn.net/home/waleedalfaris/localGPT/notebooks/~/localGPT/venv/lib/python3.10/site-packages/langchain/llms/base.py:491), in BaseLLM._generate_helper(self, prompts, stop, run_managers, new_arg_supported, **kwargs)
    481 def _generate_helper(
    482     self,
    483     prompts: List[str],
   (...)
    487     **kwargs: Any,
    488 ) -> LLMResult:
    489     try:
    490         output = (
--> 491             self._generate(
    492                 prompts,
    493                 stop=stop,
    494                 # TODO: support multiple run managers
    495                 run_manager=run_managers[0] if run_managers else None,
    496                 **kwargs,
    497             )
    498             if new_arg_supported
    499             else self._generate(prompts, stop=stop)
    500         )
    501     except (KeyboardInterrupt, Exception) as e:
    502         for run_manager in run_managers:

File [~/localGPT/venv/lib/python3.10/site-packages/langchain/llms/base.py:985](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a224c4c4d227d.vscode-resource.vscode-cdn.net/home/waleedalfaris/localGPT/notebooks/~/localGPT/venv/lib/python3.10/site-packages/langchain/llms/base.py:985), in LLM._generate(self, prompts, stop, run_manager, **kwargs)
    979 for prompt in prompts:
    980     text = (
    981         self._call(prompt, stop=stop, run_manager=run_manager, **kwargs)
    982         if new_arg_supported
    983         else self._call(prompt, stop=stop, **kwargs)
    984     )
--> 985     generations.append([Generation(text=text)])
    986 return LLMResult(generations=generations)

File [~/localGPT/venv/lib/python3.10/site-packages/langchain/load/serializable.py:74](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a224c4c4d227d.vscode-resource.vscode-cdn.net/home/waleedalfaris/localGPT/notebooks/~/localGPT/venv/lib/python3.10/site-packages/langchain/load/serializable.py:74), in Serializable.__init__(self, **kwargs)
     73 def __init__(self, **kwargs: Any) -> None:
---> 74     super().__init__(**kwargs)
     75     self._lc_kwargs = kwargs

File [~/localGPT/venv/lib/python3.10/site-packages/pydantic/main.py:341](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a224c4c4d227d.vscode-resource.vscode-cdn.net/home/waleedalfaris/localGPT/notebooks/~/localGPT/venv/lib/python3.10/site-packages/pydantic/main.py:341), in pydantic.main.BaseModel.__init__()

ValidationError: 1 validation error for Generation
text
  str type expected (type=type_error.str)
```

### Who can help?

@hwchase17
@agola11

### Information

- [ ] The official example notebooks/scripts
- [X] My own modified scripts

### Related Components

- [ ] LLMs/Chat Models
- [ ] Embedding Models
- [ ] Prompts / Prompt Templates / Prompt Selectors
- [ ] Output Parsers
- [ ] Document Loaders
- [ ] Vector Stores / Retrievers
- [ ] Memory
- [ ] Agents / Agent Executors
- [ ] Tools / Toolkits
- [X] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

```python
from langchain.chains.summarize import load_summarize_chain
from langchain.prompts import PromptTemplate
from langchain.document_loaders import PDFMinerLoader
from langchain.llms import LlamaCpp

kwargs = {
    "model_path": model_path,
    "n_ctx": 4096,
    "max_tokens": 4096,
    "seed": 42,
    "n_gpu_layers": -1,
    "verbose": True,
}
llm = LlamaCpp(**kwargs)

file = 'test_file.pdf'
loader = PDFMinerLoader(file)
docs = loader.load_and_split()
chain = load_summarize_chain(llm, chain_type='map_reduce')
summary = chain.run(docs)
print(summary)
```

### Expected behavior

The chain should provide a summary of the Documents provided