createTool only uses inputSchema for validation

Tool class accepts 4 schemas and it seems only inputSchema is used for actual validation. My expectation was that that all schemas is used to enforce runtime safety and better error reporting.
6 Replies
Guria
GuriaOP3w ago
Apparently inputSchema is also used in kind of weird way.
// Validate input if schema exists
const { data, error } = validateToolInput(this.inputSchema, context, this.id);
if (error) {
return error as any;
}
// Validate input if schema exists
const { data, error } = validateToolInput(this.inputSchema, context, this.id);
if (error) {
return error as any;
}
I am concerned about runtime safety based on that caller side can't differentiate valid data from error state.
Guria
GuriaOP3w ago
Here typescript claims I'll get particular data shape in result which is QraphQL response. But instead I get something completely different:
{
error: true,
message:
'Tool validation failed for gitlab-graphql-query. Please fix the following errors and try again:\n' +
'- query: Expected string, received number\n' +
'- variables: Expected object, received string\n' +
'\n' +
'Provided arguments: {\n' +
' "query": 12345,\n' +
' "variables": "not-an-object"\n' +
'}',
validationErrors: {
_errors: [],
query: { _errors: [ 'Expected string, received number' ] },
variables: { _errors: [ 'Expected object, received string' ] }
}
}
{
error: true,
message:
'Tool validation failed for gitlab-graphql-query. Please fix the following errors and try again:\n' +
'- query: Expected string, received number\n' +
'- variables: Expected object, received string\n' +
'\n' +
'Provided arguments: {\n' +
' "query": 12345,\n' +
' "variables": "not-an-object"\n' +
'}',
validationErrors: {
_errors: [],
query: { _errors: [ 'Expected string, received number' ] },
variables: { _errors: [ 'Expected object, received string' ] }
}
}
vs expected:
const res: {
data?: unknown;
errors?: {
message: string;
path?: (string | number)[] | undefined;
locations?: {
line: number;
column: number;
}[] | undefined;
}[] | undefined;
}
const res: {
data?: unknown;
errors?: {
message: string;
path?: (string | number)[] | undefined;
locations?: {
line: number;
column: number;
}[] | undefined;
}[] | undefined;
}
No description
Mastra Triager
GitHub
[DISCORD:1424455846188027965] createTool only uses inputSchema for ...
This issue was created from Discord post: https://discord.com/channels/1309558646228779139/1424455846188027965 Tool class accepts 4 schemas and it seems only inputSchema is used for actual validati...
Daniel Lew
Daniel Lew3w ago
Hmm I can't seem to reproduce this, if I add an outputSchema I get the types for it
No description
Daniel Lew
Daniel Lew3w ago
I'm also not sure I 100% follow what you're saying here, are you able to provide me a reproduction so I can understand what you're seeing vs what you're expecting?
Guria
GuriaOP3w ago
exactly. you only have types inferred, without runtime validation. I see no value to construct zod schemas just for type inferring poorly written execute function that uses assertions and any types inside would easely brake this contract it isn't a blocker but it breaks developer experience with wrong expectations

Did you find this page helpful?