langchain: Pydantic error: extra fields not permitted for chain_type_kwargs
Version: langchain-0.0.102
I am trying to run through the Custom Prompt guide here. Here’s some code I’m trying to run:
from langchain.prompts import PromptTemplate
from langchain import OpenAI, VectorDBQA
prompt_template = """Use the following pieces of context to answer the question at the end. If you don't know the answer, just say that you don't know, don't try to make up an answer.
{context}
Question: {question}
Answer in Italian:"""
PROMPT = PromptTemplate(
template=prompt_template, input_variables=["context", "question"]
)
chain_type_kwargs = {"prompt": PROMPT}
qa = VectorDBQA.from_chain_type(llm=OpenAI(), chain_type="stuff", vectorstore=docsearch, chain_type_kwargs=chain_type_kwargs)
I get the following error:
File /usr/local/lib/python3.10/dist-packages/langchain/chains/vector_db_qa/base.py:127, in VectorDBQA.from_chain_type(cls, llm, chain_type, **kwargs)
125 """Load chain from chain type."""
126 combine_documents_chain = load_qa_chain(llm, chain_type=chain_type)
--> 127 return cls(combine_documents_chain=combine_documents_chain, **kwargs)
File /usr/local/lib/python3.10/dist-packages/pydantic/main.py:342, in pydantic.main.BaseModel.__init__()
ValidationError: 1 validation error for VectorDBQA
chain_type_kwargs
extra fields not permitted (type=value_error.extra)
About this issue
- Original URL
- State: open
- Created a year ago
- Reactions: 4
- Comments: 30 (4 by maintainers)
I think this is so bad library, no one care about to update the documents.
What I have found is that I need to run pip install -U langchain everyday. And then make sure my code reflects the changes in the Langchain classes. These guys are moving so fast that the source code changes regularly. What worked a week ago might not work today. Its an exciting ride.
🤖
Based on the error message you provided, it seems like the
VectorDBQA
class is not expecting achain_type_kwargs
argument. Thechain_type_kwargs
argument is not defined in theVectorDBQA
class, and Pydantic is raising an error because it does not allow extra fields that are not explicitly defined in the model.The
VectorDBQA
class in the LangChain codebase is a subclass ofBaseQAWithSourcesChain
. It is used for question-answering with sources over a vector database. The class has the following attributes:vectorstore
,k
,reduce_k_below_max_tokens
,max_tokens_limit
, andsearch_kwargs
. It does not have an explicit__init__
method, so it is instantiated with the arguments that correspond to these attributes.In your code, you are trying to pass
chain_type_kwargs
as an argument toVectorDBQA.from_chain_type()
, but this method does not expect such an argument. Instead, you should pass theprompt
directly to thellm
(language model) instance. Here’s how you can modify your code:In this modified code, the
prompt
is passed directly to theOpenAI
instance when it is instantiated. Then, thisllm
instance is passed toVectorDBQA.from_chain_type()
.I hope this helps! If you have any other questions or need further clarification, feel free to ask.
Sources
About Dosu
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.
If you want to continue the conversation, start your reply with @dosu-bot.
Hi, @keviddles! I’m Dosu, and I’m here to help the LangChain team manage their backlog. I wanted to let you know that we are marking this issue as stale.
Based on the information provided, it seems that users are encountering Pydantic validation errors related to extra fields not being permitted for certain classes in the
langchain
library, such asVectorDBQA
andHuggingFaceInstructEmbeddings
. Several users have reported similar errors and have attempted to update and reinstall the library, but the issue persists. Some users have suggested runningpip install -U langchain
andpip install langchain
as a potential solution. However, there hasn’t been an official resolution or response from the repository maintainers.Could you please confirm if this issue is still relevant to the latest version of the LangChain repository? If it is, kindly let the LangChain team know by commenting on this issue. Otherwise, feel free to close the issue yourself, or it will be automatically closed in 7 days.
Thank you for your understanding and cooperation. Let me know if you have any further questions or concerns!
still getting the same error with RetrievalQA setting the chain_type as anything different than “stuff”
its open source, so you can actually contribute and write better documentation. Its a library with over 55K stars for a reason. 😃
have the same issue but with retrievalQA.from_chain_type(llm=llm,chain_type=“map_reduce”…etc) validation error for map-reducedocumentschain extra fields not permitted(type=value_error.extra)
Worked for me.
pip install -U langchain
pip install langchain
It works for me that I used the most violent method possible. comment the error code line C:\Users\xxx.conda\envs\chatglm\Lib\site-packages\pydantic\v1\main.py line 341
values, fields_set, validation_error = validate_model(__pydantic_self__.__class__, data)
# if validation_error:
# raise validation_error
@baskaryan Could you please help @kennethwork101 with this issue? They are encountering Pydantic validation errors related to extra fields not being permitted for certain classes in the
langchain
library, even after updating to version 0.0.340. They have provided additional details in their comment. Thank you!Same issue with ConversationRetrievalChain.from_llm(llm = …, chain_type=“map_reduce”, question_promt=…, combine_prompt=…)