RetrievalQA raises ValueError: Missing some input keys
ValueError: Missing some input keys: {'query'}Short answer
RetrievalQA reads the question from an input key whose default name is query and writes the answer to result. If you pass the question under another key such as question or input, the chain raises a ValueError about missing input keys. Pass a dictionary with query, or switch to the newer retrieval chain, which uses input and answer.
Fix it fast
1Find out which cause you have
Ask the chain which keys it wants and which it returns. The names it prints are the only ones that work.
python -c "from my_app import qa_chain; print(qa_chain.input_keys, qa_chain.output_keys)"2Match what you see, then jump to its fix
What does the error look like?
ValueError: Missing some input keys: {'query'}
Cause 1 of 2
The question is passed under a different key name
1Check
In the source of the retrieval QA base class the defaults are input_key equal to query and output_key equal to result. Compare these names with the dictionary in your call.
grep -n "invoke\|__call__" my_app.py2Fix
Use the key query for the question and read the answer from result.
response = qa_chain.invoke({"query": "What is the refund period?"})
print(response["result"])3Verify
The call returns a dictionary instead of raising.
print(response.keys())Confirmed by raw.githubusercontent.com
Cause 2 of 2
You moved to the replacement chain but kept the old key names
1Check
The langchain-classic reference for RetrievalQA shows the replacement chain being called with an input key, so the old and new chains do not share key names.
python -c "print(chain.input_schema.model_json_schema())"2Fix
Send input to the new chain and read answer from its result.
response = chain.invoke({"input": "What is the refund period?"})
print(response["answer"])3Verify
The reply has an answer key.
print(response.keys())Confirmed by reference.langchain.com
How do I stop it coming back?
- Wrap the chain call in one small function so the key names live in a single place.
- After changing the chain type, print input_keys again before touching callers.
- Set return_source_documents only when you need it; it adds a source_documents key to the output.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- stegnor.comMy company site: 804 pages from a Python and Jinja generator, with 15 free browser tools.
- MenuloA restaurant discovery platform in Germany, kept current by a Python ingestion pipeline.
- ShopGoAn e-commerce aggregator with a Python scraping engine behind its catalog, past 10K Google Play downloads.
Related fixes
AI
ModuleNotFoundError for langchain.chains, or RetrievalQA that will not import
ImportError: cannot import name 'RetrievalQA' from 'langchain.chains'
LangChain 1.x moved its legacy chains out of the langchain package into langchain-classic, so langchain.chains and RetrievalQA are gone from the old path.
2 causes, each with a fixAI
Azure OpenAI says the API deployment for this resource does not exist
The API deployment for this resource does not exist
Azure OpenAI does not take a model name in the model field.
2 causes, each with a fixAI
Azure OpenAI fails with an SSL certificate verification error
httpx.ConnectError: [SSL: CERTIFICATE_VERIFY_FAILED]
The client checks the endpoint's certificate against its CA bundle, which is certifi by default.
2 causes, each with a fixAI
LangChain says it could not import the chromadb package
ImportError: Could not import chromadb python package. Please install it with `pip install chromadb`.
The message comes from LangChain's old Chroma class, which cannot import chromadb in the Python that runs your code.
2 causes, each with a fixAI
Gemini API returns 429 RESOURCE_EXHAUSTED on the free tier
429 RESOURCE_EXHAUSTED
Gemini limits are applied per Google Cloud project, not per API key, so a new key in the same project does not reset anything.
3 causes, each with a fixAI
ChatPromptTemplate is missing the variable agent_scratchpad
Expected: ['agent_scratchpad', 'input']
A tool-calling agent keeps its tool calls and tool results in a prompt slot named agent_scratchpad.
2 causes, each with a fix