Normandy.Tools.Input
(normandy v2.2.0)
View Source
Validates a tool call's input before the tool runs.
The dispatcher checks the model's input here and passes the result to
Normandy.Tool.run/2 as context.input; it never goes into the tool struct.
- A tool that declared
input: Schema(use Normandy.Tool) gets a%Schema{}. Every key (string or atom) must name a field of the schema; the values are checked byNormandy.Schema.Validator(types, required fields, enums, ranges, formats; nothing is coerced, so"5"for an integer field is an error); missing optional fields take their defaults. - Any other tool gets a string-keyed map checked against its
Normandy.Tool.input_schema/1map (string or atom keys): everyrequiredkey present, each value's basic JSON type (string,integer,number,boolean,object,array,null) where its property declares one, and unknown keys as follows. A schema that declarespropertiesis closed: no key outside them unlessadditionalPropertiesistrueor a schema (an absentadditionalPropertiescounts asfalsehere, unlike JSON Schema's default). A schema with nopropertieskey declares no keys, so it limits none: any key is accepted (an MCP server's loose{"type": "object"}keeps working). Nested schemas, enums and formats are the tool's to check. Atypename outside the seven above (a typo such as"intger") is not checked: any value passes it. Aninput_schema/1that returns something other than a map, or a map whosepropertiesis not a map or whoserequiredis not a list of key names, is an error (constraint: :schema).
An unknown key is an error for a declared input schema and for a map that declares
properties, and keys are matched against declared names, so model input never creates an
atom. A key that is neither a string nor an atom is always an unknown key, named by its type
("a tuple key"). Errors are %{path: [key], message: String.t(), constraint: atom()}; message/1 joins them into one line for the model.
Summary
Functions
One line for the model: errors joined by "; ", each as "<path> <message>" (a
path-less error is its message alone).
Validates input against tool's input schema; see the moduledoc.
Types
Functions
One line for the model: errors joined by "; ", each as "<path> <message>" (a
path-less error is its message alone).
iex> Normandy.Tools.Input.message([%{path: [:query], message: "is required", constraint: :required}])
"query is required"
Validates input against tool's input schema; see the moduledoc.