Missing some input keys: {'context'} when using ConversationalRetrievalChain
Labels: name: area: memory, name: auto:bug, name: area: models

I am trying to create a `ConversationalRetrievalChain` with memory, `return_source_document=True` and a custom retriever which returns content and url of the document. I am able to generate the right response when I call the chain for the first time. But when I call it again with memory I am getting error Missing some input keys: {'context'}

Here is the trace of the error. 

```
Missing some input keys: {'context'}
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[470], line 1
----> 1 contracts_chain("How can I apply for a TPA?")
File /mnt/xarfuse/uid-560402/653248bf-seed-nspid4026531836_cgpid28389965-ns-4026531840/langchain/chains/base.py:258, in Chain.__call__(self, inputs, return_only_outputs, callbacks, tags, metadata, include_run_info)
    256 except (KeyboardInterrupt, Exception) as e:
    257     run_manager.on_chain_error(e)
--> 258     raise e
    259 run_manager.on_chain_end(outputs)
    260 final_outputs: Dict[str, Any] = self.prep_outputs(
    261     inputs, outputs, return_only_outputs
    262 )
File /mnt/xarfuse/uid-560402/653248bf-seed-nspid4026531836_cgpid28389965-ns-4026531840/langchain/chains/base.py:252, in Chain.__call__(self, inputs, return_only_outputs, callbacks, tags, metadata, include_run_info)
    246 run_manager = callback_manager.on_chain_start(
    247     dumpd(self),
    248     inputs,
    249 )
    250 try:
    251     outputs = (
--> 252         self._call(inputs, run_manager=run_manager)
    253         if new_arg_supported
    254         else self._call(inputs)
    255     )
    256 except (KeyboardInterrupt, Exception) as e:
    257     run_manager.on_chain_error(e)
File /mnt/xarfuse/uid-560402/653248bf-seed-nspid4026531836_cgpid28389965-ns-4026531840/langchain/chains/conversational_retrieval/base.py:126, in BaseConversationalRetrievalChain._call(self, inputs, run_manager)
    124 if chat_history_str:
    125     callbacks = _run_manager.get_child()
--> 126     new_question = self.question_generator.run(
    127         question=question, chat_history=chat_history_str, callbacks=callbacks
    128     )
    129 else:
    130     new_question = question
File /mnt/xarfuse/uid-560402/653248bf-seed-nspid4026531836_cgpid28389965-ns-4026531840/langchain/chains/base.py:456, in Chain.run(self, callbacks, tags, metadata, *args, **kwargs)
    451     return self(args[0], callbacks=callbacks, tags=tags, metadata=metadata)[
    452         _output_key
    453     ]
    455 if kwargs and not args:
--> 456     return self(kwargs, callbacks=callbacks, tags=tags, metadata=metadata)[
    457         _output_key
    458     ]
    460 if not kwargs and not args:
    461     raise ValueError(
    462         "`run` supported with either positional arguments or keyword arguments,"
    463         " but none were provided."
    464     )
File /mnt/xarfuse/uid-560402/653248bf-seed-nspid4026531836_cgpid28389965-ns-4026531840/langchain/chains/base.py:235, in Chain.__call__(self, inputs, return_only_outputs, callbacks, tags, metadata, include_run_info)
    200 def __call__(
    201     self,
    202     inputs: Union[Dict[str, Any], Any],
   (...)
    208     include_run_info: bool = False,
    209 ) -> Dict[str, Any]:
    210     """Execute the chain.
    211 
    212     Args:
   (...)
    233             `Chain.output_keys`.
    234     """
--> 235     inputs = self.prep_inputs(inputs)
    236     callback_manager = CallbackManager.configure(
    237         callbacks,
    238         self.callbacks,
   (...)
    243         self.metadata,
    244     )
    245     new_arg_supported = inspect.signature(self._call).parameters.get("run_manager")
File /mnt/xarfuse/uid-560402/653248bf-seed-nspid4026531836_cgpid28389965-ns-4026531840/langchain/chains/base.py:389, in Chain.prep_inputs(self, inputs)
    387     external_context = self.memory.load_memory_variables(inputs)
    388     inputs = dict(inputs, **external_context)
--> 389 self._validate_inputs(inputs)
    390 return inputs
File /mnt/xarfuse/uid-560402/653248bf-seed-nspid4026531836_cgpid28389965-ns-4026531840/langchain/chains/base.py:147, in Chain._validate_inputs(self, inputs)
    145 missing_keys = set(self.input_keys).difference(inputs)
    146 if missing_keys:
--> 147     raise ValueError(f"Missing some input keys: {missing_keys}")
ValueError: Missing some input keys: {'context'}
```


Here is my code
```
memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True,  output_key="answer", input_key="question")

llama2_chat_prompt = """
        

 

        You are a helpful assistant for tech company. 
        Answer question using the following conversation history and context

        Conversation History: {chat_history}

        Context: {context}
        


        Question: {question}
        Answer in Markdown:
        


        


        

        """

prompt = PromptTemplate(
    input_variables=["question", "context", "chat_history"],
    output_parser=None,
    partial_variables={},
    template=llama2_chat_prompt,
    template_format="f-string",
    validate_template=False,
    verbose=verbose,
)

llm_chain = LLMChain(llm=llm, prompt=prompt, verbose=verbose)

doc_input_variables = ["page_content", "src"]
document_prompt = PromptTemplate(
    input_variables=doc_input_variables,
    template="Content: {page_content}\nSource: {src}",
)

combine_documents_chain = StuffDocumentsChain(
    llm_chain=llm_chain,
    document_variable_name="context",
    document_prompt=document_prompt,
    verbose=verbose,
)

contracts_chain = ConversationalRetrievalChain(
            retriever=my_custom_retriver,
            memory=memory,
            question_generator=llm_chain,
            combine_docs_chain=combine_documents_chain,
            return_source_documents=False,
            verbose=verbose,
)
```

resp = contracts_chain("Can you help me?")  ## runs fine
resp1 = contracts_chain("My question is about weather")  ##  gives error.