AITools
validate_inputLast updated on
Last updated on
Validate and normalize one field, party, annex, or checklist item value
Validates one value against the artifact that owns it, without touching a draft. Use it to check each answer as a user gives it, then pass the accepted values to fill or update_fill.
Input
Takes a source plus:
| Field | Type | Required | Description |
|---|---|---|---|
target | "field" | "party" | "annex" | "checklist_item" | Yes | What the value is for |
value | unknown | Yes | The value to check. For annex, an Attachment: { name, mimeType, checksum? }. |
field_path | string | For field | Field path, such as weight |
role_id | string | For party | Party role ID, such as tenant |
index | integer | No | Party index for roles with more than one party. Default 0. |
annex_id | string | For annex | Annex ID |
item_id | string | For checklist_item | Checklist item ID |
field, party, and annex need a form. checklist_item needs a checklist.
Output
| Field | Type | Description |
|---|---|---|
valid | boolean | Whether the value passed |
target | string | The requested target |
artifact_kind | string | Artifact kind, when detected |
normalized_value | unknown | The value as the artifact stores it, when valid |
errors | ToolError[] | Why the value failed. validation_error for a bad value, invalid_target for a target the artifact does not have. |
error | ToolError | Set when validation could not run |
Direct usage
import { executeValidateInput } from "@paradoc/ai-tools"
const source = {
source: "registry",
registry_url: "https://public.paradoc.dev",
artifact_name: "pet-addendum",
} as const
const weight = await executeValidateInput({
...source,
target: "field",
field_path: "weight",
value: 45,
})
const tenant = await executeValidateInput({
...source,
target: "party",
role_id: "tenant",
value: { id: "tenant-0", name: "Jane Doe" },
})Example responses
Valid field
{
"valid": true,
"target": "field",
"artifact_kind": "form",
"normalized_value": 45
}Valid party
{
"valid": true,
"target": "party",
"artifact_kind": "form",
"normalized_value": {
"roleId": "tenant",
"index": 0,
"party": { "id": "tenant-0", "name": "Jane Doe" }
}
}Invalid value
{
"valid": false,
"target": "field",
"artifact_kind": "form",
"errors": [
{
"code": "validation_error",
"message": "Must be one of: dog, cat, fish",
"path": ["fields", "species"]
}
]
}