Find answers from the community

Updated 2 months ago

I have started getting this error in subquestionoutputparser sub_questions = [SubQuest

I have started getting this error in subquestionoutputparser
sub_questions = [SubQuestion.parse_obj(item) for item in json_dict]
File "pydantic/main.py", line 525, in pydantic.main.BaseModel.parse_obj
pydantic.error_wrappers.ValidationError: 1 validation error for SubQuestion
root
SubQuestion expected dict not str (type=type_error)
k
s
L
15 comments
Please stand by @sriani as I search the knowledge base. We are experiencing especially high traffic right now and might take longer than usual. :wave:
----------------------
The error message you're seeing is from Pydantic, a data validation library used in Python. It's indicating that when trying to parse a SubQuestion object, it expected a dictionary (dict), but received a string (str) instead.

This error is likely due to the format of json_dict not being what the SubQuestion.parse_obj() method expects. The SubQuestion.parse_obj() method is expecting a dictionary with keys and values that match the data model of the SubQuestion class.

To resolve this issue, you need to ensure that json_dict is indeed a list of dictionaries, where each dictionary corresponds to a SubQuestion object. If json_dict is a string, you might need to parse it into a Python object using json.loads() or a similar method.

Unfortunately, the extracts provided do not contain the exact code for the SubQuestion class or the json_dict variable, so I can't provide a more specific solution. However, you can refer to the LlamaIndex documentation and examples for more information on how to use Pydantic models and the SubQuestionQueryEngine:

  • Guidance for Sub-Question Query Engine ()
  • Guidance ()
Remember, the key is to ensure that the data you're trying to parse into a SubQuestion object matches the expected structure.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
@kapa.ai @Logan M Any specific version of it works with ? It was just fine a few minutes back
Let me check the knowledge base for you. One moment! :books:
----------------------
Based on the information provided in the extracts, there's no specific mention of a version of LlamaIndex that works with the SubQuestion class or the SubQuestionQueryEngine.

However, it's generally a good practice to ensure that you're using a version of the library that's compatible with your code. If your code was working fine a few minutes ago, it's possible that a recent update or change in your environment might have caused the issue.

If you've recently updated LlamaIndex or any other related library (like Pydantic), you might want to try reverting back to the version you were using when everything was working fine.

If you haven't made any changes recently, then the issue might be due to some change in the data you're processing. You might want to check the data that's being passed to the SubQuestion.parse_obj() method to ensure it's in the correct format.

Unfortunately, without more specific information about your environment and the versions of the libraries you're using, it's hard to provide a more specific solution. You might find it helpful to refer to the LlamaIndex documentation or the source code to get more information about the expected data formats and any version-specific requirements.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
This is just a parsing error, my guess is the model didn't output in the correct format :PSadge:
BaseOutputParser is failing and apart from generating the subquestions it is giving an empty string in the end
class SubQuestionOutputParser(BaseOutputParser):
def parse(self, output: str) -> Any:
json_dict = parse_json_markdown(output)
sub_questions = [SubQuestion.parse_obj(item) for item in json_dict]
return StructuredOutput(raw_output=output, parsed_output=sub_questions)

def format(self, prompt_template: str) -> str:
del prompt_template
raise NotImplementedError()
Is there a quick way to fix this ?
Like I mentioned, it's failing because the LLM is not generating questions with the proper format.

You can try changing LLMs and see if it improves, or try changing the question you are asking
@kapa.ai Is there a way i can send me prompt for sub question generation , give example
Let me check the knowledge base for you. One moment! :books:
----------------------
Yes, you can customize the prompt for sub-question generation in LlamaIndex. This is done by implementing a custom QuestionGenerator and plugging it into the SubQuestionQueryEngine. Here's an example of how to do this using the GuidanceQuestionGenerator:

Plain Text
from llama_index.question_gen.guidance_generator import GuidanceQuestionGenerator
from guidance.llms import OpenAI as GuidanceOpenAI

# define guidance based question generator
question_gen = GuidanceQuestionGenerator.from_defaults(guidance_llm=GuidanceOpenAI('text-davinci-003'), verbose=False)

# define query engine tools
query_engine_tools = ...

# construct sub-question query engine
s_engine = SubQuestionQueryEngine.from_defaults(
    question_gen=question_gen,  # use guidance based question_gen defined above
    query_engine_tools=query_engine_tools, 
)


In this example, the GuidanceQuestionGenerator is used to generate sub-questions. The guidance_llm parameter is set to GuidanceOpenAI('text-davinci-003'), which specifies the language model to use for generating the sub-questions.

You can replace GuidanceQuestionGenerator with your own custom QuestionGenerator to further customize the sub-question generation process.

For more details, you can refer to the LlamaIndex documentation on guidance ().
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
that will actually help
guidance is good
Add a reply
Sign up and join the conversation on Discord