Define data models for parsing and validating text
Model
base class. This is a lightweight wrapper around
pydantic-xml’s BaseXMLModel
with some added features and functionality to make it easy for Rigging to manage. In general this includes:
.from_text()
method for the details..to_pretty_xml()
to get new-line formatted outputs..fact
) isn’t relevant to the XML structure. We only use this to access the contents of that model field in code. However the name of our model (FunFact
) is relevant to the XML representation. What you name your models is important to how the underlying LLM interprets it’s meaning. You should be thoughtful and descriptive about your model names as they affect how well the LLM understands the intention, and how likely it is to output one model over another (based on it’s token probability distribution).
If you want to separate the model tag from it’s class name, you specify it in the class construction:
make_primitive()
utility. The interior field will always be named .content
and typed depending on the argument passed.
bool
, int
, and float
.
bool
type, which means pydantic will accept standard values which could be reasonably interpreted as a boolean. We also added a custom field validator to check for instances of yes/no
as text strings. All of these XML values will parse correctly into the YesNoAnswer
model, so you can handle cases where the LLM outputs a variety of different
.xml_tags()
or .xml_example()
works well for communicating to the model how it should respond, however for more complex models it’s highly recommended to overload the .xml_example()
method to provide a more detailed example of the XML structure you expect.
The easiest way to approach this overload is to instantiate your model class with a few standard values and use .to_prety_xml()
.