Skip to content

Commit a8e98dc

Browse files
feat: Added ExcludeValues + Fixed issue with regex matching type. (#1818)
## Description ### This PR introduces a new excludedValues field for tool parameters, enhancing validation capabilities. This change introduces a new excludedValues field for tool parameters. This field allows developers to specify a list of values that are not allowed for a parameter. The excludedValues field supports both exact value matching and regular expression matching. The changes include: - Updating the tool parameter documentation to include the excludedValues field. - Adding the excludedValues field to the CommonParameter struct. - Implementing the logic to check for excluded values in the Parse method of each parameter type. - Updating the MatchStringOrRegex function to support non-string inputs by converting them to strings before regex matching. This makes the allowedValues and excludedValues checks more robust. - Adding unit tests for allowedValues to verify the MatchStringOrRegex change on parameters. - Adding unit tests to verify the excludedValues functionality. ## PR Checklist - [x] Make sure you reviewed CONTRIBUTING.md (httpshttps://github.com/googleapis/genai-toolbox/blob/main/CONTRIBUTING.md) - [x] Make sure to open an issue as a bug/issue (https://github.com/googleapis/genai-toolbox/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [x] Ensure the tests and linter pass - [x] Code coverage does not decrease (if any source code was changed) - [x] Appropriate docs were updated (if necessary) - [ ] Make sure to add ! if this involve a breaking change 🛠️ Fixes #1792 Co-authored-by: Averi Kitsch <akitsch@google.com>
1 parent 4797751 commit a8e98dc

3 files changed

Lines changed: 372 additions & 37 deletions

File tree

‎docs/en/resources/tools/_index.md‎

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,18 @@ the parameter.
7777
description: Airline unique 2 letter identifier
7878
```
7979

80-
| **field** | **type** | **required** | **description** |
81-
|---------------|:--------------:|:------------:|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
82-
| name | string | true | Name of the parameter. |
83-
| type | string | true | Must be one of "string", "integer", "float", "boolean" "array" |
84-
| description | string | true | Natural language description of the parameter to describe it to the agent. |
85-
| default | parameter type | false | Default value of the parameter. If provided, `required` will be `false`. |
86-
| required | bool | false | Indicate if the parameter is required. Default to `true`. |
87-
| allowedValues | []string | false | Input value will be checked against this field. Regex is also supported. |
88-
| escape | string | false | Only available for type `string`. Indicate the escaping delimiters used for the parameter. This field is intended to be used with templateParameters. Must be one of "single-quotes", "double-quotes", "backticks", "square-brackets". |
89-
| minValue | int or float | false | Only available for type `integer` and `float`. Indicate the minimum value allowed. |
90-
| maxValue | int or float | false | Only available for type `integer` and `float`. Indicate the maximum value allowed. |
80+
| **field** | **type** | **required** | **description** |
81+
|----------------|:--------------:|:------------:|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
82+
| name | string | true | Name of the parameter. |
83+
| type | string | true | Must be one of "string", "integer", "float", "boolean" "array" |
84+
| description | string | true | Natural language description of the parameter to describe it to the agent. |
85+
| default | parameter type | false | Default value of the parameter. If provided, `required` will be `false`. |
86+
| required | bool | false | Indicate if the parameter is required. Default to `true`. |
87+
| allowedValues | []string | false | Input value will be checked against this field. Regex is also supported. |
88+
| excludedValues | []string | false | Input value will be checked against this field. Regex is also supported. |
89+
| escape | string | false | Only available for type `string`. Indicate the escaping delimiters used for the parameter. This field is intended to be used with templateParameters. Must be one of "single-quotes", "double-quotes", "backticks", "square-brackets". |
90+
| minValue | int or float | false | Only available for type `integer` and `float`. Indicate the minimum value allowed. |
91+
| maxValue | int or float | false | Only available for type `integer` and `float`. Indicate the maximum value allowed. |
9192

9293
### Array Parameters
9394

@@ -108,15 +109,16 @@ in the list using the items field:
108109
SELECT * FROM airlines WHERE preferred_airlines = ANY($1);
109110
```
110111

111-
| **field** | **type** | **required** | **description** |
112-
|---------------|:----------------:|:------------:|----------------------------------------------------------------------------|
113-
| name | string | true | Name of the parameter. |
114-
| type | string | true | Must be "array" |
115-
| description | string | true | Natural language description of the parameter to describe it to the agent. |
116-
| default | parameter type | false | Default value of the parameter. If provided, `required` will be `false`. |
117-
| required | bool | false | Indicate if the parameter is required. Default to `true`. |
118-
| allowedValues | []string | false | Input value will be checked against this field. Regex is also supported. |
119-
| items | parameter object | true | Specify a Parameter object for the type of the values in the array. |
112+
| **field** | **type** | **required** | **description** |
113+
|----------------|:----------------:|:------------:|----------------------------------------------------------------------------|
114+
| name | string | true | Name of the parameter. |
115+
| type | string | true | Must be "array" |
116+
| description | string | true | Natural language description of the parameter to describe it to the agent. |
117+
| default | parameter type | false | Default value of the parameter. If provided, `required` will be `false`. |
118+
| required | bool | false | Indicate if the parameter is required. Default to `true`. |
119+
| allowedValues | []string | false | Input value will be checked against this field. Regex is also supported. |
120+
| excludedValues | []string | false | Input value will be checked against this field. Regex is also supported. |
121+
| items | parameter object | true | Specify a Parameter object for the type of the values in the array. |
120122

121123
{{< notice note >}}
122124
Items in array should not have a `default` or `required` value. If provided, it
@@ -247,15 +249,16 @@ tools:
247249
escape: double-quotes # with this, the statement will resolve to `SELECT "id", "name" FROM flights`
248250
```
249251

250-
| **field** | **type** | **required** | **description** |
251-
|---------------|:----------------:|:---------------:|-------------------------------------------------------------------------------------|
252-
| name | string | true | Name of the template parameter. |
253-
| type | string | true | Must be one of "string", "integer", "float", "boolean", "array" |
254-
| description | string | true | Natural language description of the template parameter to describe it to the agent. |
255-
| default | parameter type | false | Default value of the parameter. If provided, `required` will be `false`. |
256-
| required | bool | false | Indicate if the parameter is required. Default to `true`. |
257-
| allowedValues | []string | false | Input value will be checked against this field. Regex is also supported. |
258-
| items | parameter object | true (if array) | Specify a Parameter object for the type of the values in the array (string only). |
252+
| **field** | **type** | **required** | **description** |
253+
|----------------|:----------------:|:---------------:|-------------------------------------------------------------------------------------|
254+
| name | string | true | Name of the template parameter. |
255+
| type | string | true | Must be one of "string", "integer", "float", "boolean", "array" |
256+
| description | string | true | Natural language description of the template parameter to describe it to the agent. |
257+
| default | parameter type | false | Default value of the parameter. If provided, `required` will be `false`. |
258+
| required | bool | false | Indicate if the parameter is required. Default to `true`. |
259+
| allowedValues | []string | false | Input value will be checked against this field. Regex is also supported. |
260+
| excludedValues | []string | false | Input value will be checked against this field. Regex is also supported. |
261+
| items | parameter object | true (if array) | Specify a Parameter object for the type of the values in the array (string only). |
259262

260263
## Authorized Invocations
261264

0 commit comments

Comments
 (0)