Structured output allows you to always format responses according to a specific input JSON schema. As of now, the following models support structured output under PremSDK:
gpt-4o
gpt-4o-mini
To invoke function calling, you need to define a JSON schema and pass that schema inside the response_format argument. Here is an example to get started with structured output using PremAI SDK.
To understand structured output, you should have an understanding of the Prem SDK. If not, please check that out first.
ResponseChoice( index=0, message=Message( role=<MessageRoleEnum.ASSISTANT: 'assistant'>, content='{"steps":[{"explanation":"The World Series in Major League Baseball is the annual championship series between the champions of the American League (AL) and the National League (NL). Every year, teams from thesetwo leagues compete to win the prestigious title.","output":"The World Series is a championship series in Major League Baseball."},{"explanation":"To find the winner, we can check records or historical data from the 2020 MLB season. The 2020 World Series was significant due to its occurrence during the COVID-19 pandemic, which affected the season.","output":"The 2020 MLB season was affected by the COVID-19 pandemic."},{"explanation":"The 2020 MLB World Series took place later in the year than usual, from October 20 to October 27.","output":"The 2020 World Series was held from October 20 to October 27."},{"explanation":"The two teams competing in the 2020 World Series were the Los Angeles Dodgers from the National League and the Tampa Bay Rays from the American League.","output":"The Los Angeles Dodgers and the Tampa Bay Rays competed in the 2020 World Series."},{"explanation":"The Los Angeles Dodgers have been prominent in the National League and have participated in multiple World Series over the past decade.","output":"The Dodgers have been a consistently competitive team in recent years."},{"explanation":"The Los Angeles Dodgers won the 2020 World Series by defeating the Tampa Bay Rays 4games to 2 in the best-of-seven series.","output":"The Dodgers defeated the Rays 4-2 to win the series."}],"final_answer":"The Los Angeles Dodgers won the World Series in 2020."}', template_id=<premai.types.Unset object at 0x7c294ffdabf0>, params=<premai.types.Unset object at 0x7c294ffdabf0>, additional_properties={'tool_calls': None} ), finish_reason='stop', tool_calls=<premai.types.Unset object at 0x7c294ffdabf0>, additional_properties={})
Structured Output is still on early phases. We are going to bring more improvements in near future starting from supporting structured outputs on other LLMs and support for pydantic and Zod in our SDK.