Find answers from the community

Updated 3 months ago

Logan M I m having an issue with

I'm having an issue with guidance_utils script of llama_index after upgrading to pydantic v2.30. Here is my error: File "/Users/vinodvarma/Documents/GitHub/talktodata-api/ai.py", line 138, in parse_sql_results program = GuidancePydanticProgram( File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/llama_index/program/guidance_program.py", line 42, in __init__ output_str = pydantic_to_guidance_output_template_markdown(output_cls) File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/llama_index/prompts/guidance_utils.py", line 54, in pydantic_to_guidance_output_template_markdown output = json_schema_to_guidance_output_template(cls.schema(), root=cls.schema()) File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/llama_index/prompts/guidance_utils.py", line 89, in json_schema_to_guidance_output_template + json_schema_to_guidance_output_template(v, k, indent + 1, root) File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/llama_index/prompts/guidance_utils.py", line 107, in json_schema_to_guidance_output_template + json_schema_to_guidance_output_template(schema["items"], "this", 0, root) File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/llama_index/prompts/guidance_utils.py", line 79, in json_schema_to_guidance_output_template root["definitions"][model], key, indent, root KeyError: 'definitions' -----------Any clue why this this is happening?
L
v
5 comments
hmm what happens if you do print(output_cls.schema()) in the terminal?

Since guidance is using a pydantic object, there might be some incompatibility here πŸ€” The latest versions of llama-index technically support pydantic 2, but only with thier compatbility layer (i.e. from pydantic.v1 import BaseModel)

You may have to define your output_cls with the v1 base model?
This is the output of print(output_cls.schema()):
{'$defs': {'ColumnName': {'properties': {'column_name': {'title': 'Column Name', 'type': 'string'}}, 'required': ['column_name'], 'title': 'ColumnName', 'type': 'object'}}, 'properties': {'column_names': {'items': {'$ref': '#/$defs/ColumnName'}, 'title': 'Column Names', 'type': 'array'}}, 'required': ['column_names'], 'title': 'Columns', 'type': 'object'}
Can you throw some light on how to solve this ?
Yea, this is a v1/v2 error I think?

Define your output_cls using v1

Plain Text
from pydantic.v1 import BaseModel

class OutputCLS(BaseModel):
  ...
Perfect, I 'm able to solve this, Thanks @Logan M
Add a reply
Sign up and join the conversation on Discord