AITools

validate_input

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:

FieldTypeRequiredDescription
target"field" | "party" | "annex" | "checklist_item"YesWhat the value is for
valueunknownYesThe value to check. For annex, an Attachment: { name, mimeType, checksum? }.
field_pathstringFor fieldField path, such as weight
role_idstringFor partyParty role ID, such as tenant
indexintegerNoParty index for roles with more than one party. Default 0.
annex_idstringFor annexAnnex ID
item_idstringFor checklist_itemChecklist item ID

field, party, and annex need a form. checklist_item needs a checklist.

Output

FieldTypeDescription
validbooleanWhether the value passed
targetstringThe requested target
artifact_kindstringArtifact kind, when detected
normalized_valueunknownThe value as the artifact stores it, when valid
errorsToolError[]Why the value failed. validation_error for a bad value, invalid_target for a target the artifact does not have.
errorToolErrorSet 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"]
    }
  ]
}

On this page