Find answers from the community

Updated 3 months ago

Hi! I remember while creating pydantic

Hi! I remember while creating pydantic models for pydantic program, there was a way to explain what each field in a class represent, e.g:

Plain Text
class ClimateChangeTarget(BaseModel):
    """Data model for climate change target"""
    target_reduction_of_emission: str # I want to write what I mean by this field
    base_year: int # I want to write what I mean by this field
    timeline: str # I want to write what I mean by this field
    target_description: str # I want to write what I mean by this field


class Data101Model(BaseModel):
    """Data model for climate change targets"""
    overall_target: ClimateChangeTarget  # I want to write what I mean by this field
    scope_1: ClimateChangeTarget # I want to write what I mean by this field
    scope_2: ClimateChangeTarget # I want to write what I mean by this field
    scope_3: ClimateChangeTarget # I want to write what I mean by this field


How to declare my fields with explanations of each field?
L
p
4 comments
Plain Text
from llama_index.core.bridge.pydantic import BaseModel, Field

class MyClass(BaseModel):
  name: str = Field(description="Name of the thing.")
Thanks @Logan M !

Do those descriptions help LLM to understand what each field represents? If yes, then how?

I could not find a section in the docs where it’s been explained
They get used when converting the object to a schema
In the openai api
Add a reply
Sign up and join the conversation on Discord