response_format to a Pydantic model, and Curator asks the model for output that matches it. Your parse method then gets an instance of that model instead of a string.
Generate poems with structured output
- The Pydantic models
PoemandPoemsdescribe the output you want from the LLM. Poetsetsresponse_format = Poems. You can also passresponse_format=Poemswhen you create the object.- For each topic,
promptbuilds the prompt and Curator sends it to the LLM. parsegets aPoemsobject and returns one row for each poem, with the topic next to it.
Chain LLM calls
You can pass the output of oneLLM object to the next. In this example, a Muse generates the topics and the Poet from above writes poems about them.
muse() has no input, so Curator sends one request. You can pass the CuratorResponse it returns straight to poet. Each step fans out the rows of the step before it, so a short chain can produce a large dataset.
Not every model supports structured output. If a model does not support it, Curator raises an error before it sends any requests.