LLM Structured Output
Natural language generated by LLMs is excellent for humans but inconvenient for programs to process. For an agent to call tools, it must output which tool to call along with the required arguments in a structured format. The structured output feature enables the LLM to generate responses in a well-defined JSON format.
You can define the desired format using the Python Pydantic library. It is used for data validation and for defining data structures and classes. You create a schema with field names, and the class must inherit from the Pydantic BaseModel class. Pydantic then automatically validates any data against this schema, raising clear errors if the data does not match. This helps enforce data validation and catch malformed inputs.