Skip to content
BountiesProductsAgentsLedgerDocs
Bounties
agent / agent-validateBuilt by davevia claude-codeRuns on Liberas

Tool input validation

validate(schema, input), both JSON text, before a tool runs (ADR 0062). Errors, in this order: "schema is not JSON"; the schema's shape; "input is not JSON". A schema is true, false or an object; the keywords read are type, const, enum, required, properties, additionalProperties, items, minItems, maxItems, uniqueItems, minLength, maxLength, minimum, maximum, exclusiveMinimum, exclusiveMaximum, allOf, anyOf, oneOf and not; every other keyword (pattern, format, $ref, …) is ignored. Shape: a subschema that is neither a boolean nor an object is the error "schema {pointer}: not a schema" (pointer: its JSON Pointer, "" at the root); at each schema object the keywords present are checked in ascending byte order of their names, the first malformed one giving "schema {pointer}: {keyword} is malformed": type a string or a non-empty array of strings among array, boolean, integer, null, number, object, string; enum a non-empty array; required an array of strings; properties an object whose values are schemas; additionalProperties, items and not schemas; allOf, anyOf and oneOf non-empty arrays of schemas; minItems, maxItems, minLength and maxLength numbers that are non-negative integers (a float without a fraction counts); minimum, maximum, exclusiveMinimum and exclusiveMaximum numbers; uniqueItems a boolean; const anything. After a schema's own keywords its subschemas are checked, depth first, in the same byte order of keyword names (additionalProperties, allOf, anyOf, items, not, oneOf, properties), the arrays by index and properties by key byte order. Validation walks the input once and collects every problem {path, message}, path the value's JSON Pointer ("" at the root; ~ and / in a token become ~0 and ~1): true accepts; false is "nothing is allowed here"; type: "expected {the types, joined by " or ", in the schema's order}, got {actual}" with actual one of null, boolean, number, string, array, object, where integer accepts a number without a fractional part; const: "expected the constant {the constant as compact JSON, object keys in byte order}" unless equal; enum: "not one of the allowed values" unless equal to one; equality is as JSON values with numbers by value (1 equals 1.0). Then by the input's type. An object: "missing required property {name}" for each required name absent, in required order; then each property in key byte order: one named in properties is validated by that schema at path/name, otherwise additionalProperties false gives "unexpected property {name}" at the object's path, an additionalProperties schema validates it at path/name, and nothing else happens. An array: "at least {n} items", "at most {n} items", "items must be unique" (equality as above), then items validates each element at path/index. A string: "at least {n} characters", "at most {n} characters", counting Unicode scalar values. A number: "must be >= {n}", "must be > {n}", "must be <= {n}", "must be < {n}" for minimum, exclusiveMinimum, maximum, exclusiveMaximum in that order, compared as IEEE doubles. Then, for any type: allOf appends each subschema's problems in order; anyOf gives "matches none of the alternatives" when no subschema accepts; oneOf gives "matches {k} alternatives, not exactly one" unless exactly one accepts; not gives "must not match the excluded schema" when its schema accepts. A subschema under anyOf, oneOf or not reports nothing of its own. A number in a message is written without a fraction when it has none, else as the shortest decimal that reads back.

From your terminal

terminal
npm i -g https://liberas.dev/cli/liberas.tgz
export LIBERAS_URL=https://liberas.dev
liberas init agent-validate --lang rust
cd agent-validate && liberas build && liberas submit

Save a token once with liberas login (make it on your page, /me, after signing in). init scaffolds the interface, the vectors and a stub in Rust (--lang js for light specs).

Interface (WIT)21 lines›
agent-validate.wit
package root:component;

world root {
  import liberas:agent/types@0.1.0;

  export liberas:agent/validate@0.1.0;
}
package liberas:agent@0.1.0 {
  interface types {
    record problem {
      path: string,
      message: string,
    }
  }
  interface validate {
    use types.{problem};

    validate: func(schema: string, input: string) -> result<list<problem>, string>;
  }
}
Test vectors38›
agent-validate.cases.json
[
  {
    "args": {
      "input": "{\"path\":\"a\"}",
      "schema": "{\"type\":\"object\",\"properties\":{\"path\":{\"type\":\"string\"}},\"required\":[\"path\"],\"additionalProperties\":false}"
    }
  },
  {
    "args": {
      "input": "{\"path\":1}",
      "schema": "{\"type\":\"object\",\"properties\":{\"path\":{\"type\":\"string\"}},\"required\":[\"path\"],\"additionalProperties\":false}"
    }
  },
  {
    "args": {
      "input": "{\"paths\":\"a\",\"x\":null}",
      "schema": "{\"type\":\"object\",\"properties\":{\"path\":{\"type\":\"string\"}},\"required\":[\"path\"],\"additionalProperties\":false}"
    }
  },
  {
    "args": {
      "input": "\"not an object\"",
      "schema": "{\"type\":\"object\",\"properties\":{\"path\":{\"type\":\"string\"}},\"required\":[\"path\"],\"additionalProperties\":false}"
    }
  },
  {
    "args": {
      "input": "{",
      "schema": "{\"type\":\"object\",\"properties\":{\"path\":{\"type\":\"string\"}},\"required\":[\"path\"],\"additionalProperties\":false}"
    }
  },
  {
    "args": {
      "input": "{}",
      "schema": "{"
    }
  },
  {
    "args": {
      "input": "[1,2]",
      "schema": "true"
    }
  },
  {
    "args": {
      "input": "null",
      "schema": "false"
    }
  },
  {
    "args": {
      "input": "null",
      "schema": "{\"type\":[\"string\",\"null\"]}"
    }
  },
  {
    "args": {
      "input": "1.5",
      "schema": "{\"type\":[\"string\",\"null\"]}"
    }
  },
  {
    "args": {
      "input": "2.0",
      "schema": "{\"type\":\"integer\"}"
    }
  },
  {
    "args": {
      "input": "2.5",
      "schema": "{\"type\":\"integer\"}"
    }
  },
  {
    "args": {
      "input": "{\"a\":\"x\",\"b\":[1.0,2]}",
      "schema": "{\"const\":{\"b\":[1,2.0],\"a\":\"x\"}}"
    }
  },
  {
    "args": {
      "input": "{\"a\":\"x\",\"b\":[1,3]}",
      "schema": "{\"const\":{\"b\":[1,2.0],\"a\":\"x\"}}"
    }
  },
  {
    "args": {
      "input": "[3]",
      "schema": "{\"enum\":[1,\"two\",null,[3]]}"
    }
  },
  {
    "args": {
      "input": "3",
      "schema": "{\"enum\":[1,\"two\",null,[3]]}"
    }
  },
  {
    "args": {
      "input": "{\"zz\":1,\"a\":1,\"b\":-1,\"c\":true}",
      "schema": "{\"type\":\"object\",\"required\":[\"b\",\"a\"],\"properties\":{\"a\":{\"type\":\"string\"},\"b\":{\"type\":\"number\",\"minimum\":0}},\"additionalProperties\":{\"type\":\"boolean\"}}"
    }
  },
  {
    "args": {
      "input": "[1,1.0,11,2]",
      "schema": "{\"type\":\"array\",\"minItems\":2,\"maxItems\":3,\"uniqueItems\":true,\"items\":{\"type\":\"integer\",\"maximum\":10}}"
    }
  },
  {
    "args": {
      "input": "[5]",
      "schema": "{\"type\":\"array\",\"minItems\":2,\"items\":{\"type\":\"string\"}}"
    }
  },
  {
    "args": {
      "input": "\"한글\"",
      "schema": "{\"type\":\"string\",\"minLength\":2,\"maxLength\":3}"
    }
  },
  {
    "args": {
      "input": "\"a\"",
      "schema": "{\"type\":\"string\",\"minLength\":2,\"maxLength\":3}"
    }
  },
  {
    "args": {
      "input": "\"abcd\"",
      "schema": "{\"type\":\"string\",\"minLength\":2,\"maxLength\":3}"
    }
  },
  {
    "args": {
      "input": "1",
      "schema": "{\"minimum\":1,\"exclusiveMinimum\":1,\"maximum\":1,\"exclusiveMaximum\":1}"
    }
  },
  {
    "args": {
      "input": "0.25",
      "schema": "{\"minimum\":0.5,\"maximum\":1e21}"
    }
  },
  {
    "args": {
      "input": "3",
      "schema": "{\"minimum\":1.5,\"maximum\":2.5}"
    }
  },
  {
    "args": {
      "input": "\"ab\"",
      "schema": "{\"allOf\":[{\"type\":\"string\"},{\"minLength\":3}],\"anyOf\":[{\"type\":\"number\"},{\"const\":\"abc\"}],\"oneOf\":[{\"type\":\"string\"},{\"minLength\":1}],\"not\":{\"maxLength\":5}}"
    }
  },
  {
    "args": {
      "input": "\"abc\"",
      "schema": "{\"anyOf\":[{\"type\":\"number\"},{\"const\":\"abc\"}],\"oneOf\":[{\"type\":\"number\"},{\"type\":\"string\"}],\"not\":{\"type\":\"null\"}}"
    }
  },
  {
    "args": {
      "input": "{\"a/b\":{\"c~d\":1}}",
      "schema": "{\"properties\":{\"a/b\":{\"properties\":{\"c~d\":{\"type\":\"null\"}}}}}"
    }
  },
  {
    "args": {
      "input": "{\"x\":\"zzz\"}",
      "schema": "{\"type\":\"object\",\"properties\":{\"x\":{\"pattern\":\"^a$\",\"format\":\"email\",\"$ref\":\"#/nope\"}}}"
    }
  },
  {
    "args": {
      "input": "1",
      "schema": "{\"type\":\"strin\"}"
    }
  },
  {
    "args": {
      "input": "1",
      "schema": "{\"properties\":{\"a\":{\"items\":5}}}"
    }
  },
  {
    "args": {
      "input": "1",
      "schema": "{\"required\":[\"a\",1]}"
    }
  },
  {
    "args": {
      "input": "[]",
      "schema": "{\"minItems\":-1}"
    }
  },
  {
    "args": {
      "input": "[]",
      "schema": "{\"minItems\":2.0,\"anyOf\":[]}"
    }
  },
  {
    "args": {
      "input": "1",
      "schema": "{\"allOf\":[true,{\"not\":\"no\"}]}"
    }
  },
  {
    "args": {
      "input": "[]",
      "schema": "{\"uniqueItems\":\"yes\",\"type\":\"array\"}"
    }
  },
  {
    "args": {
      "input": "1",
      "schema": "[]"
    }
  },
  {
    "args": {
      "input": "{\"deep\":[{\"id\":1},{\"id\":0},{\"no\":1},5]}",
      "schema": "{\"type\":\"object\",\"properties\":{\"deep\":{\"type\":\"array\",\"items\":{\"type\":\"object\",\"required\":[\"id\"],\"properties\":{\"id\":{\"type\":\"integer\",\"exclusiveMinimum\":0}}}}}}"
    }
  }
]
Versions (units)1›
  1. v1by davef80c48dfa7stable 5.1.0latestconfirmed10/23/2026
Verification7›
  • Outputs must match the private reference implementation bit for bit.
  • Cases are the spec's 38 vectors plus ones generated from the interface's types: edge values and random ones seeded by your component's hash.
  • Components may import nothing but specs: no files, no network, no clock.
  • Runs on Liberas: the component never leaves the platform, and every call is metered on the ledger.
  • A remote call may execute up to 200,000,000 instructions.
  • Already built: a component that passes and uses at most 0.9× the current one's fuel on the same cases replaces it, and earns the spec's shares in proportion to the saving.
  • Found an input where the current component disagrees with the spec? Submit it as a case (API or `liberas case`): it joins the vectors for good and earns 10% of the spec's shares. A component that then passes replaces the broken one for 25%.