I keep running into an error that says the argument should be of type (SquadExample, dict) when working on my RAG implementation. The documentation doesn’t really explain how to structure the SquadExample dictionary properly.
Here’s my current setup:
template = """
You are a financial data assistant. Please answer based on the provided context.
query: {query}
data: {data}
"""
CHAIN_TEMPLATE = PromptTemplate(template=template, input_variables=["query", "data"])
user_query = "How did average income change across US regions from 2020 to 2023?"
from langchain.chains import create_retrieval_chain
from langchain.chains.combine_documents import create_stuff_documents_chain
from langchain_core.prompts import ChatPromptTemplate
sys_message = (
"You are a financial assistant helping with query {query}."
"Reference: {data}"
)
chat_template = ChatPromptTemplate.from_messages(
[
("system", sys_message),
("user", "{query}"),
]
)
doc_chain = create_stuff_documents_chain(model, CHAIN_TEMPLATE)
full_chain = create_retrieval_chain(vector_db.as_retriever(), doc_chain)
response = full_chain.invoke({"input": user_query, "query": user_query})
I tried looking up create_sample methods but I’m still confused about the implementation. Anyone know the correct way to handle this?
The retrieval chain automatically passes documents as ‘context’ and user input as ‘input’. You were trying to override this with custom variables which breaks the internal schema validation.
Spent weeks debugging similar template mismatches when I was building our company’s document search system. The SquadExample error is just LangChain’s confusing way of saying your variable names don’t match what it expects.
Your invoke call’s the problem - you’re passing both ‘input’ and ‘query’ when retrieval chains only want ‘input’. Drop the query parameter and just use full_chain.invoke({"input": user_query}). Your system message template’s also using wrong variable names. Should be {input} and {context} since retrieval chains provide those automatically. I hit this exact issue last month and wasted way too much time before realizing retrieval chains handle context injection internally - you don’t need to manually pass data variables.
you’re mixin up the prompt templates - you got both CHAIN_TEMPLATE and chat_template but only using one. drop the extra and just use ChatPromptTemplate for the doc chain. that SquadExample error usually pops up when templates don’t match.
You’re mixing incompatible template types in your document chain. When you call create_stuff_documents_chain(model, CHAIN_TEMPLATE), you’re passing a basic PromptTemplate instead of a ChatPromptTemplate. Switch that line to create_stuff_documents_chain(model, chat_template). Your system message formatting is also wrong - change it to "You are a financial assistant helping with query {input}. Reference: {context}". Retrieval chains expect ‘input’ and ‘context’ variables, not ‘query’ and ‘data’. The SquadExample error pops up because your custom variable names don’t match the expected schema. Fix the variable names and the error should go away.