diff --git a/fern/pages/v2/text-generation/parameter-types-in-json.mdx b/fern/pages/v2/text-generation/parameter-types-in-json.mdx
new file mode 100644
index 00000000..86ae2e57
--- /dev/null
+++ b/fern/pages/v2/text-generation/parameter-types-in-json.mdx
@@ -0,0 +1,458 @@
+---
+title: "Parameter Types in Structured Outputs (JSON)"
+slug: "v2/docs/parameter-types-in-json"
+
+hidden: false
+
+description: "This page shows usage examples of the JSON Schema parameter types supported in Structured Outputs (JSON)."
+image: "../../../assets/images/f1cc130-cohere_meta_image.jpg"
+keywords: "Cohere, language models, structured outputs"
+
+createdAt: "Thu Jun 06 2024 05:37:56 GMT+0000 (Coordinated Universal Time)"
+updatedAt: "Tue Jun 11 2024 02:43:00 GMT+0000 (Coordinated Universal Time)"
+---
+
+This page provides usage examples of the JSON Schema parameters that are supported in [Structured Outputs (JSON)](https://docs.cohere.com/v2/docs/structured-outputs).
+
+Note: Using Structured Outputs (JSON), the outputs are guaranteed to follow the schema for the tool name, parameter name, parameter data types, and the list of required parameters.
+
+
+
+The examples on this page each provide a `response_format` schema and a `message` (the user message). To get an output, pass those values to a Chat endpoint call, as shown in the helper code below.
+
+```python PYTHON
+import cohere
+co = cohere.ClientV2(api_key="YOUR API KEY")
+
+res = co.chat(
+ # The model name. Example: command-r-plus-08-2024
+ model="MODEL_NAME",
+ # The user message. Optional - you can first add a `system_message` role
+ messages=[
+ {
+ "role": "user",
+ "content": message,
+ }
+ ],
+ # The schema that you define
+ response_format=response_format,
+ # Typically, you'll need a low temperature for more deterministic outputs
+ temperature=0
+)
+
+print(res.message.content[0].text)
+```
+
+
+## Basic types
+
+### String
+
+```python PYTHON
+response_format={
+ "type": "json_object",
+ "schema": {
+ "type": "object",
+ "properties": {
+ "title": {"type": "string"},
+ "author": {"type": "string"},
+ },
+ "required": ["title", "author"],
+ },
+}
+
+message = "Generate a JSON describing a book, with the fields 'title' and 'author'"
+```
+
+Example output:
+
+```mdx wordWrap
+{
+ "title": "The Great Gatsby",
+ "author": "F. Scott Fitzgerald"
+}
+```
+
+### Integer
+
+```python PYTHON
+response_format={
+ "type": "json_object",
+ "schema": {
+ "type": "object",
+ "properties": {
+ "title": {"type": "string"},
+ "author": {"type": "string"},
+ "publication_year": {"type": "integer"},
+ },
+ "required": ["title", "author", "publication_year"],
+ },
+}
+
+message = "Generate a JSON describing a book, with the fields 'title', 'author' and 'publication_year'"
+```
+
+Example output:
+
+```mdx wordWrap
+{
+ "title": "The Great Gatsby",
+ "author": "F. Scott Fitzgerald",
+ "publication_year": 1925
+}
+```
+
+### Float
+
+```python PYTHON
+response_format={
+ "type": "json_object",
+ "schema": {
+ "type": "object",
+ "properties": {
+ "city": {"type": "string"},
+ "temperature": {"type": "number"},
+ },
+ "required": ["city", "temperature"],
+ },
+}
+
+message = "Generate a JSON of a city and its average daily temperature in celcius"
+```
+
+Example output:
+
+```mdx wordWrap
+{
+ "city": "Toronto",
+ "temperature": 15.6
+}
+```
+
+### Boolean
+
+```python PYTHON
+response_format={
+ "type": "json_object",
+ "schema": {
+ "type": "object",
+ "properties": {
+ "city": {"type": "string"},
+ "is_capital": {"type": "boolean"},
+ },
+ "required": ["city", "is_capital"],
+ },
+}
+
+message = "Generate a JSON about a city in Spain and whether it is the capital of its country using 'is_capital'."
+```
+
+Example output:
+
+```mdx wordWrap
+{
+ "city": "Madrid",
+ "is_capital": true
+}
+```
+
+## Array
+
+### With specific types
+
+```python PYTHON
+response_format={
+ "type": "json_object",
+ "schema": {
+ "type": "object",
+ "properties": {
+ "cities": {
+ "type": "array",
+ "items": {"type": "string"},
+ }
+ },
+ "required": ["cities"],
+ },
+}
+
+message = "Generate a JSON listing three cities in Japan."
+```
+
+Example output:
+
+```mdx wordWrap
+{
+ "cities": [
+ "Tokyo",
+ "Kyoto",
+ "Osaka"
+ ]
+}
+```
+
+### Without specific types
+
+```python PYTHON
+response_format={
+ "type": "json_object",
+ "schema": {
+ "type": "object",
+ "properties": {
+ "cities": {
+ "type": "array",
+ }
+ },
+ "required": ["cities"],
+ },
+}
+
+message = "Generate a JSON listing three cities in Japan."
+```
+
+Example output:
+
+```mdx wordWrap
+{
+ "cities": [
+ "Tokyo",
+ "Kyoto",
+ "Osaka"
+ ]
+}
+```
+
+### Lists of lists
+
+```python PYTHON
+response_format={
+ "type": "json_object",
+ "schema": {
+ "type": "object",
+ "properties": {
+ "coordinates": {
+ "type": "array",
+ "items": {
+ "type": "array",
+ "items": {"type": "number"},
+ }
+ }
+ },
+ "required": ["coordinates"],
+ },
+}
+
+message = "Generate a JSON of three random coordinates."
+```
+
+Example output:
+
+```mdx wordWrap
+{
+ "coordinates": [
+ [-31.28333, 146.41667],
+ [78.95833, 11.93333],
+ [44.41667, -75.68333]
+ ]
+}
+```
+
+## Others
+
+### Nested objects
+
+```python PYTHON
+response_format = {
+ "type": "json_object",
+ "schema": {
+ "type": "object",
+ "properties": {
+ "actions": {
+ "type": "array",
+ "items": {
+ "type": "object",
+ "properties": {
+ "japanese": {"type": "string"},
+ "romaji": {"type": "string"},
+ "english": {"type": "string"},
+ },
+ "required": ["japanese", "romaji", "english"],
+ },
+ }
+ },
+ "required": ["actions"],
+ },
+}
+
+message = "Generate a JSON array of 3 objects with the following fields: japanese, romaji, english. These actions should be japanese verbs provided in the dictionary form."
+```
+
+Example output:
+
+```mdx wordWrap
+{
+ "actions": [
+ {
+ "japanese": "食べる",
+ "romaji": "taberu",
+ "english": "to eat"
+ },
+ {
+ "japanese": "話す",
+ "romaji": "hanasu",
+ "english": "to speak"
+ },
+ {
+ "japanese": "書く",
+ "romaji": "kaku",
+ "english": "to write"
+ }
+ ]
+}
+```
+
+### Enums
+
+```python PYTHON
+response_format={
+ "type": "json_object",
+ "schema": {
+ "type": "object",
+ "properties": {
+ "genre": {"type": "string",
+ "enum": ["historical fiction", "cozy mystery"]},
+ "title": {"type": "string"}
+ },
+ "required": ["title", "genre"],
+ },
+}
+
+message = "Generate a JSON for a new book idea."
+```
+
+Example output:
+
+```mdx wordWrap
+{
+ "genre": "historical fiction",
+ "title": "The Unseen Thread: A Tale of the Silk Road's Secrets and Shadows"
+ }
+```
+
+### Const
+
+```python PYTHON
+response_format={
+ "type": "json_object",
+ "schema": {
+ "type": "object",
+ "properties": {
+ "city": {
+ "type": "object",
+ "properties": {
+ "country": {"type": "string", "const": "Thailand"},
+ "city_name": {"type": "string"},
+ "avg_temperature": {"type": "number"},
+
+ },
+ "required": ["country", "city_name", "avg_temperature"]
+ }
+ },
+ "required": ["city"],
+ },
+}
+
+message = "Generate a JSON of a city."
+```
+
+Example output:
+
+```mdx wordWrap
+{
+ "city": {
+ "country": "Thailand",
+ "city_name": "Bangkok",
+ "avg_temperature": 29.083333333333332
+ }
+}
+```
+
+### Pattern
+
+```python PYTHON
+response_format={
+ "type": "json_object",
+ "schema": {
+ "type": "object",
+ "properties": {
+ "product_sku": {
+ "type": "string",
+ "pattern": "[A-Z]{3}[0-9]{7}"
+ }
+ },
+ "required": ["product_sku"],
+ },
+}
+
+message = "Generate a JSON of an SKU for a new product line."
+```
+
+Example output:
+
+```mdx wordWrap
+{
+ "product_sku": "PRX0012345"
+}
+```
+
+### Format
+
+```python PYTHON
+response_format={
+ "type": "json_object",
+ "schema": {
+ "type": "object",
+ "properties": {
+ "itinerary": {
+ "type": "array",
+ "items": {
+ "type": "object",
+ "properties": {
+ "day_number": {"type": "integer"},
+ "date": {"type": "string",
+ "format": "date"},
+ "places_to_visit": {"type": "string"}
+ },
+ "required": ["day_number", "date", "places_to_visit"]
+ }
+ }
+ },
+ "required": ["itinerary"],
+ },
+}
+
+message = "Generate a JSON of a 3-day visit of Bali starting Jan 5 2025."
+```
+
+Example output:
+
+```mdx wordWrap
+{
+ "itinerary": [
+ {
+ "day_number": 1,
+ "date": "2025-01-05",
+ "places_to_visit": "Tanah Lot Temple, Ubud Monkey Forest, Tegalalang Rice Terraces"
+ },
+ {
+ "day_number": 2,
+ "date": "2025-01-06",
+ "places_to_visit": "Mount Batur, Tirta Empul Temple, Ubud Art Market"
+ },
+ {
+ "day_number": 3,
+ "date": "2025-01-07",
+ "places_to_visit": "Uluwatu Temple, Kuta Beach, Seminyak"
+ }
+ ]
+}
+```
\ No newline at end of file
diff --git a/fern/pages/v2/text-generation/structured-outputs.mdx b/fern/pages/v2/text-generation/structured-outputs.mdx
index 2865aaa3..1f91ee33 100644
--- a/fern/pages/v2/text-generation/structured-outputs.mdx
+++ b/fern/pages/v2/text-generation/structured-outputs.mdx
@@ -18,10 +18,10 @@ updatedAt: "Tue Jun 11 2024 02:43:00 GMT+0000 (Coordinated Universal Time)"
Structured Outputs is a feature for forcing the LLM's output to follow a specified format 100% of the time. This increases the reliability of LLM in enterprise applications where downstream applications expect the LLM output to be correctly formatted. By forcing the model to follow a structured schema, hallucinated fields and entries in structured data can be reliably eliminated.
Compatible models:
-- Command R 08 2024
-- Command R
- Command R+ 08 2024
- Command R+
+- Command R 08 2024
+- Command R
## How to Use Structured Outputs
@@ -140,7 +140,7 @@ Note: Each schema provided (in both JSON and Tools modes) will incur a latency o
### Structured Outputs (Tools)
-When you use the Chat API with `tools`, setting the `strict_tools` parameter to `true` will enforce that every generated tool call follows the specified tool schema.
+When you use the Chat API with `tools`, setting the `strict_tools` parameter to `True` will enforce that every generated tool call follows the specified tool schema.
`strict_tools` is currently an experimental parameter. We’ll be iterating on this feature and are looking for feedback. Share your experience with us in the `#api-discussions` channel on [discord](https://discord.gg/co-mmunity) or via [email](mailto:support@cohere.com).
@@ -150,9 +150,9 @@ With `strict_tools` enabled, the API will ensure that the tool names and tool pa
Additionally, this results in faster development. You don’t need to spend a lot of time prompt engineering the model to avoid hallucinations.
-In the example below, we create a tool that can retrieve weather data for a given location. The tool is called`get_weather` which contains a parameter called `location`. We then invoke the Chat API with `strict_tools` set to `true` to ensure that the generated tool calls always include the correct function and parameter names.
+In the example below, we create a tool that can retrieve weather data for a given location. The tool is called `get_weather` which contains a parameter called `location`. We then invoke the Chat API with `strict_tools` set to `True` to ensure that the generated tool calls always include the correct function and parameter names.
-When the `strict_tools` parameter is set to `true`, you can define a maximum of 200 fields across all tools being passed to an API call.
+When the `strict_tools` parameter is set to `True`, you can define a maximum of 200 fields across all tools being passed to an API call.
```python PYTHON {24}
tools = [
@@ -214,11 +214,70 @@ When constructing a `schema` keep the following constraints in mind:
- The `type` in the top level schema must be `object`
- Every object in the schema must have at least one `required` field specified
+## Parameter types support
+
+### Supported schema features
+
+The Structured Outputs feature (both JSON and Tools mode) relies on the JSON Schema notation for defining the parameters. JSON Schema allows developers to specify the expected format of JSON objects, ensuring that the data adheres to predefined rules and constraints.
+
+Structured Outputs supports a subset of the JSON Schema specification, detailed in the tables below. This is broken down into three categories:
+- Structured Outputs (JSON)
+- Structured Outputs (Tools) - When `strict_tools` is set to `True`
+- Tool Use - When `strict_tools` is set to `False`
+
+#### Basic types
+
+| Parameter | [Structured Outputs (JSON)](#) | [Structured Outputs (Tools)](https://docs.cohere.com/v2/docs/tool-use#structured-outputs-tools) | [Tool Use](https://docs.cohere.com/v2/docs/tool-use) |
+| --- | --- | --- | --- |
+| String | Yes | Yes | Yes |
+| Integer | Yes | Yes | Yes |
+| Float | Yes | Yes | Yes |
+| Boolean | Yes | Yes | Yes |
+
+See usage examples for [JSON](https://docs.cohere.com/v2/docs/parameter-types-in-json#basic-types) and [Tools](https://docs.cohere.com/v2/docs/parameter-types-in-tool-use#basic-types).
+
+
+#### Arrays
+
+| Parameter | [Structured Outputs (JSON)](#) | [Structured Outputs (Tools)](https://docs.cohere.com/v2/docs/tool-use#structured-outputs-tools) | [Tool Use](https://docs.cohere.com/v2/docs/tool-use) |
+| --- | --- | --- | --- |
+| Arrays - With specific types | Yes | Yes | Yes |
+| Arrays - Without specific types | Yes | Yes | Yes |
+| Arrays - List of lists | Yes | Yes | Yes |
+
+See usage examples for [JSON](https://docs.cohere.com/v2/docs/parameter-types-in-json#arrays) and [Tools](https://docs.cohere.com/v2/docs/parameter-types-in-tool-use#arrays).
+
+#### Others
+
+| Parameter | [Structured Outputs (JSON)](#) | [Structured Outputs (Tools)](https://docs.cohere.com/v2/docs/tool-use#structured-outputs-tools) | [Tool Use](https://docs.cohere.com/v2/docs/tool-use) |
+| --- | --- | --- | --- |
+| Nested objects | Yes | Yes | Yes |
+| Enum | Yes | Yes | Yes |
+| Const¹ | Yes | Yes | Yes |
+| Pattern | Yes | Yes | Yes |
+| Format² | Yes | Yes | Yes |
+| $ref | Yes | Yes | Yes |
+| $def | Yes | Yes | Yes |
+| additionalProperties | Yes³ | Yes⁴ | Yes |
+| uniqueItems | No | No | Yes |
+| anyOf | Yes | Yes | Yes |
+
+¹ Const is supported for these types: `int`, `float`, `bool`, `type(None)`, `str`.
+
+² Format is supported for these values: `date-time`, `uuid`, `date`, `time`.
+
+³ In Structured Outputs (JSON), `additionalProperties` does not enforce `required`, `dependencies`, `propertyNames`, `anyOf`, `allOf`, `oneOf`.
+
+⁴ In Structured Outputs (Tools), `additionalProperties` does not enforce `required`, `dependencies`, `propertyNames`, `any Of`, `all Of`, `one Of`.
+
+See usage examples for [JSON](https://docs.cohere.com/v2/docs/parameter-types-in-json#others) and [Tools](https://docs.cohere.com/v2/docs/parameter-types-in-tool-use#others).
+
+
### Unsupported schema features
We do not support the entirety of the [JSON Schema specification](https://json-schema.org/specification). Below is a list of some unsupported features:
-- [Schema Composition](https://json-schema.org/understanding-json-schema/reference/combining#schema-composition) (`anyOf`, `allOf`, `oneOf` and `not`)
+- [Schema Composition](https://json-schema.org/understanding-json-schema/reference/combining#schema-composition) (`allOf`, `oneOf` and `not`)
- [Numeric Ranges](https://json-schema.org/understanding-json-schema/reference/numeric#range) (`maximum` and `minimum`)
- [Array Length Ranges](https://json-schema.org/understanding-json-schema/reference/array#length) (`minItems` and `maxItems`)
- String limitations:
@@ -233,6 +292,3 @@ We do not support the entirety of the [JSON Schema specification](https://json-s
- `uuid`
- `date`
- `time`
-- Others:
- - `uniqueItems`
- - `additionalProperties`
diff --git a/fern/pages/v2/text-generation/tools/parameter-types-in-tool-use.mdx b/fern/pages/v2/text-generation/tools/parameter-types-in-tool-use.mdx
index b3c9967b..f02de01b 100644
--- a/fern/pages/v2/text-generation/tools/parameter-types-in-tool-use.mdx
+++ b/fern/pages/v2/text-generation/tools/parameter-types-in-tool-use.mdx
@@ -11,129 +11,373 @@ keywords: "Cohere, AI tool use"
createdAt: "Wed Apr 24 2024 17:31:36 GMT+0000 (Coordinated Universal Time)"
updatedAt: "Wed Apr 24 2024 18:37:19 GMT+0000 (Coordinated Universal Time)"
---
-Cohere's tool use feature is available in the chat endpoint via the API and all of our SDKs (Python, Typescript, Java, Go). The functionality relies on JSON Schema type notation to define parameters. Parameters are the inputs that a tool or function needs to operate. With this approach there is flexibility to use any JSON Schema type as a definition for these parameters. This includes basic types like integers, numbers, and strings, as well as more complex types such as arrays and objects.
+This page provides usage examples of the JSON Schema parameters that are supported in [Structured Outputs (Tools)](https://docs.cohere.com/v2/docs/tool-use#structured-outputs-tools).
-Additionally, the default value for optional parameters can be provided, which will be used if no value is specified when the function is called. It is also possible to define enumerations (enums) to specify a set of valid values for a parameter, restricting the input to a predefined list of options.
+Note: When the `strict_tools` (experimental) is set to `True`, the outputs are guaranteed to follow the schema for the tool name, parameter name, parameter data types, and the list of required parameters.
-Below are some examples that illustrate how to define parameters using JSON Schema types, defaults, and enums.
+
-## Example – Simple types
+The examples on this page each provide a tool schema and a `message` (the user message). To get an output, pass those values to a Chat endpoint call, as shown in the helper code below.
+
+```python PYTHON PYTHON
+import cohere
+co = cohere.ClientV2(api_key="YOUR API KEY")
+
+res = co.chat(
+ # The model name. Example: command-r-plus-08-2024
+ model="MODEL_NAME",
+ # The user message. Optional - you can first add a `system_message` role
+ messages=[
+ {
+ "role": "user",
+ "content": message,
+ }
+ ],
+ # The tool schema that you define
+ tools=tools,
+ # This guarantes that the output will adhere to the schema
+ strict_tools=True,
+ # Typically, you'll need a low temperature for more deterministic outputs
+ temperature=0
+)
+
+for tc in response.message.tool_calls:
+ print(f"{tc.function.name} | Parameters: {tc.function.arguments}")
+```
+
+
+
+## Basic types
+
+### String
+
+```python PYTHON
+tools = [
+ {
+ "type": "function",
+ "function": {
+ "name": "get_weather",
+ "description" : "Gets the weather of a given location",
+ "parameters": {
+ "type": "object",
+ "properties": {
+ "location": {
+ "type" : "string",
+ "description": "The location to get weather."
+ }
+ },
+ "required": ["location"]
+ }
+ }
+ },
+]
+
+message = "What's the weather in Toronto?"
+```
+
+Example output:
+
+```mdx wordWrap
+get_weather
+{
+ "location": "Toronto"
+}
+```
+
+### Integer
```python PYTHON
tools = [
{
"type": "function",
"function": {
- "name": "query_daily_sales_report",
- "description": "Connects to a database to retrieve overall sales volumes and sales information for a given day.",
+ "name": "add_numbers",
+ "description": "Adds two numbers",
"parameters": {
"type": "object",
"properties": {
- "day": {
- "type": "string",
- "description": "Retrieves sales data for this day, formatted as YYYY-MM-DD."
- }
+ "first_number": {
+ "type": "integer",
+ "description": "The first number to add.",
+ },
+ "second_number": {
+ "type": "integer",
+ "description": "The second number to add.",
+ },
},
- "required": ["day"]
- }
- }
+ "required": ["first_number", "second_number"],
+ },
+ },
}
]
-message = "Can you provide a sales summary for 29th September 2023, and also give me some details about the products in the 'Electronics' category, for example their prices and stock levels?"
+message = "What is five plus two"
+```
-res = co.chat(model="command-r-plus-08-2024",
- messages=[{"role": "user", "content": message}],
- tools=tools)
+Example output:
+```mdx wordWrap
+add_numbers
+{
+ "first_number": 5,
+ "second_number": 2
+}
```
-
+### Float
-## Example – Arrays
+```python PYTHON
+tools = [
+ {
+ "type": "function",
+ "function": {
+ "name": "add_numbers",
+ "description": "Adds two numbers",
+ "parameters": {
+ "type": "object",
+ "properties": {
+ "first_number": {
+ "type": "number",
+ "description": "The first number to add.",
+ },
+ "second_number": {
+ "type": "number",
+ "description": "The second number to add.",
+ },
+ },
+ "required": ["first_number", "second_number"],
+ },
+ },
+ }
+]
-### With specific element types
+message = "What is 5.3 plus 2"
+```
+
+Example output:
+
+```mdx wordWrap
+add_numbers
+{
+ "first_number": 5.3,
+ "second_number": 2
+}
+```
+
+### Boolean
```python PYTHON
tools = [
{
"type": "function",
"function": {
- "name": "query_daily_sales_report",
- "description": "Connects to a database to retrieve overall sales volumes and sales information for numerous days.",
+ "name": "reserve_tickets",
+ "description": "Reserves a train ticket",
"parameters": {
"type": "object",
"properties": {
- "days": {
- "type": "array",
- "items": {"type": "string"},
- "description": "Retrieves sales data formatted as YYYY-MM-DD."
- }
+ "quantity": {
+ "type": "integer",
+ "description": "The quantity of tickets to reserve.",
+ },
+ "trip_protection": {
+ "type": "boolean",
+ "description": "Indicates whether to add trip protection.",
+ },
},
- "required": ["days"]
- }
- }
+ "required": ["quantity", "trip_protection"],
+ },
+ },
}
]
+
+message = "Book me 2 tickets. I don't need trip protection."
+```
+
+Example output:
+
+```mdx wordWrap
+reserve_tickets
+{
+ "quantity": 2,
+ "trip_protection": false
+}
+```
+
+## Array
+
+### With specific types
+
+```python PYTHON
+tools = [
+ {
+ "type": "function",
+ "function": {
+ "name": "get_weather",
+ "description" : "Gets the weather of a given location",
+ "parameters": {
+ "type": "object",
+ "properties": {
+ "locations": {
+ "type": "array",
+ "items": {"type": "string"},
+ "description": "The locations to get weather."
+ }
+ },
+ "required": ["locations"]
+ }
+ }
+ },
+]
+
+message = "What's the weather in Toronto and New York?"
+```
+
+Example output:
+
+```mdx wordWrap
+get_weather
+{
+ "locations": [
+ "Toronto",
+ "New York"
+ ]
+}
+```
+
+### Without specific types
+
+```python PYTHON
+tools = [
+ {
+ "type": "function",
+ "function": {
+ "name": "get_weather",
+ "description" : "Gets the weather of a given location",
+ "parameters": {
+ "type": "object",
+ "properties": {
+ "locations": {
+ "type": "array",
+ "description": "The locations to get weather."
+ }
+ },
+ "required": ["locations"]
+ }
+ }
+ },
+]
+
+message = "What's the weather in Toronto and New York?"
```
-### Without specific element types
+Example output:
+
+```mdx wordWrap
+get_weather
+{
+ "locations": [
+ "Toronto",
+ "New York"
+ ]
+}
+```
+
+### Lists of lists
```python PYTHON
tools = [
{
"type": "function",
"function": {
- "name": "query_daily_sales_report",
- "description": "Connects to a database to retrieve overall sales volumes and sales information for numerous days.",
+ "name": "maxPoints",
+ "description": "Finds the maximum number of points on a line.",
"parameters": {
"type": "object",
"properties": {
- "days": {
+ "points": {
"type": "array",
- "description": "Retrieves sales data for these days, formatted as YYYY-MM-DD."
+ "description": "The list of points. Points are 2 element lists [x, y].",
+ "items": {
+ "type": "array",
+ "items": {"type": "integer"},
+ "description": "A point represented by a 2 element list [x, y].",
+ }
}
},
- "required": ["days"]
+ "required": ["points"],
}
}
}
]
+
+message = "Please provide the maximum number of collinear points for this set of coordinates - [[1,1],[2,2],[3,4],[5,5]]."
```
-
+Example output:
+
+```mdx wordWrap
+maxPoints
+{
+ "points": [
+ [1,1],
+ [2,2],
+ [3,4],
+ [5,5]
+ ]
+}
+```
-## Example – Enumerated values (enums)
+## Others
-To make sure a tool only accepts certain values you can list those values in the parameter's description. For example, you can say "Possible enum values: customer, supplier."
+### Nested objects
```python PYTHON
tools = [
{
"type": "function",
"function": {
- "name": "fetch_contacts",
- "description": "Fetch a contact by type",
+ "name": "search_furniture_products",
+ "description": "Searches for furniture products given the user criteria.",
"parameters": {
"type": "object",
"properties": {
- "contact_type": {
+ "product_type": {
"type": "string",
- "description": "The type of contact to fetch. Possible enum values: customer, supplier.",
- }
+ "description": "The type of the product to search for.",
+ },
+ "features": {
+ "type": "object",
+ "properties": {
+ "material": {"type": "string"},
+ "style": {"type": "string"},
+ },
+ "required": ["style"],
+ },
},
- "required": ["contact_type"]
- }
- }
+ "required": ["product_type"],
+ },
+ },
}
]
+
+message = "I'm looking for a dining table made of oak in Scandinavian style."
```
-
+Example output:
-## Example - Defaults
+```mdx wordWrap
+search_furniture_products
+{
+ "features": {
+ "material": "oak",
+ "style": "Scandinavian"
+ },
+ "product_type": "dining table"
+}
+```
-To ensure a tool is called with a default value it's recommended to specify the default on the tool's implementation and use required: False whenever possible. When this is not possible you can specify the default in the parameter's description (with required: True). For example:
+### Enums
```python PYTHON
tools = [
@@ -147,7 +391,8 @@ tools = [
"properties": {
"contact_type": {
"type": "string",
- "description": "The type of contact to fetch. The default value is: supplier.",
+ "description": "The type of contact to fetch.",
+ "enum": ["customer", "supplier"]
}
},
"required": ["contact_type"]
@@ -156,8 +401,139 @@ tools = [
}
]
+message = "Give me vendor contacts."
```
+Example output:
+```mdx wordWrap
+fetch_contacts
+{
+ "contact_type": "supplier"
+}
+```
+
+### Const
+
+```python PYTHON
+tools = [
+ {
+ "type": "function",
+ "function": {
+ "name": "get_weather",
+ "description" : "Gets the weather of a given location",
+ "parameters": {
+ "type": "object",
+ "properties": {
+ "location": {
+ "type": "string",
+ "description": "The location to get weather."
+ },
+ "country": {
+ "type": "string",
+ "description": "The country for the weather lookup",
+ "const": "Canada"
+ }
+ },
+ "required": ["location", "country"]
+ }
+ }
+ },
+]
+
+message = "What's the weather in Toronto and Vancouver?"
+```
+
+Example output:
+
+```mdx wordWrap
+get_weather
+{
+ "country": "Canada",
+ "location": "Toronto"
+}
+---
+get_weather
+{
+ "country": "Canada",
+ "location": "Vancouver"
+}
+---
+```
-
+### Pattern
+
+```python PYTHON
+tools = [
+ {
+ "type": "function",
+ "function": {
+ "name": "query_product_by_sku",
+ "description": "Queries products by SKU pattern",
+ "parameters": {
+ "type": "object",
+ "properties": {
+ "sku_pattern": {
+ "type": "string",
+ "description": "Pattern to match SKUs",
+ "pattern": "[A-Z]{3}[0-9]{4}"
+ }
+ },
+ "required": ["sku_pattern"]
+ }
+ }
+ }
+]
+
+message = "Check the stock level of this product - 7374 hgY"
+```
+
+Example output:
+
+```mdx wordWrap
+query_product_by_sku
+{
+ "sku_pattern": "HGY7374"
+}
+```
+
+### Format
+
+```python PYTHON
+tools = [
+ {
+ "type": "function",
+ "function": {
+ "name": "book_hotel",
+ "description": "Books a hotel room for a specific check-in date",
+ "parameters": {
+ "type": "object",
+ "properties": {
+ "hotel_name": {
+ "type": "string",
+ "description": "Name of the hotel"
+ },
+ "check_in_date": {
+ "type": "string",
+ "description": "Check-in date for the hotel",
+ "format": "date"
+ }
+ },
+ "required": ["hotel_name", "check_in_date"]
+ }
+ }
+ }
+]
+
+message = "Book a room at the Grand Hotel with check-in on Dec 2 2024"
+```
+
+Example output:
+
+```mdx wordWrap
+book_hotel
+{
+ "check_in_date": "2024-12-02",
+ "hotel_name": "Grand Hotel"
+}
+```
diff --git a/fern/v2.yml b/fern/v2.yml
index 9baf8b93..ccdd3747 100644
--- a/fern/v2.yml
+++ b/fern/v2.yml
@@ -65,8 +65,12 @@ navigation:
path: pages/v2/text-generation/chat-api.mdx
- page: Streaming Responses
path: pages/v2/text-generation/streaming.mdx
- - page: Structured Outputs
- path: pages/v2/text-generation/structured-outputs.mdx
+ - section: Structured Outputs
+ contents:
+ - page: Structured Outputs
+ path: pages/v2/text-generation/structured-outputs.mdx
+ - page: Parameter Types in Structured Outputs (JSON)
+ path: pages/v2/text-generation/parameter-types-in-json.mdx
- page: Predictable Outputs
path: pages/v2/text-generation/predictable-outputs.mdx
- page: Advanced Generation Parameters