Structured Outputs

Besides SDK we support setting output schemas as well. In this page we will show you how to set output schema for forcing LLM to generate output in a specific format. Output schema is a JSON object that describes the structure of the output. This can be anything from a simple JSON object to a complex nested structure.

Note: We will use Scraper tool in our examples. You can get the API Key from ScrapingBee’s website

Natural Language Schema

This is a simple and intuitive way to define the output schema. It can be anything.

1workflows:
2 - anthropic:
3 llm: claude-3-haiku-20240307
4 name: Structured Assistant
5 tools:
6 - scraper:
7 name: browser
8 use_for: searching the internet
9 metadata:
10 apiKey: <YOUR_SCRAPINGBEE_API_KEY>
11 prompt: You're a helpful assistant.
12 output_schema: |-
13 [
14 {
15 product_url: Product URL that links to the Amazon page
16 product_name: Name of the product
17 product_price: Price of the product in U.S dollars
18 }
19 ]

JSON Schema

JSON schema is more powerful than natural language schema. It allows you to define the output schema in a more structured way.

1workflows:
2 - anthropic:
3 llm: claude-3-haiku-20240307
4 name: Structured Assistant
5 tools:
6 - scraper:
7 name: browser
8 use_for: searching the internet
9 metadata:
10 apiKey: <YOUR_SCRAPINGBEE_API_KEY>
11 prompt: You're a helpful assistant.
12 output_schema:
13 type: array
14 items:
15 type: object
16 required:
17 - product_url
18 - product_name
19 - product_price
20 properties:
21 product_url:
22 type: string
23 product_name:
24 type: string
25 product_price:
26 type: number
27 description: the price of the product in U.S dollars

For example, you can ask for I need a list of books about programming from Amazon.. The scraper tool will scrape the data from Amazon’s website and return the data in the format you have defined in the output schema.