Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
AI and LLM integration

RetrievalQA raises ValueError: Missing some input keys

ErrorValueError: 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.

  • Applies to Python 3.12, langchain-classic 1.x
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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)"
  2. 2Match what you see, then jump to its fix

    1. 1The call looks like qa_chain.invoke({"question": ...}) or ({"input": ...})The question is passed under a different key nameFix
    2. 2The code builds the chain with create_retrieval_chain and still sends queryYou moved to the replacement chain but kept the old key namesFix

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.py

2Fix

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

Did this fix it?

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

Did this fix it?

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:

Related fixes

AI

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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.