Output of tool.execute is typed incorrectly or gives errors
Tools
The object that is returned from tool.execute is incorrectly typed. It's now typed as
ValidationError<Any> | Whatever the output scheme of the defined tool is
ValidationError<Any> | Whatever the output scheme of the defined tool is
let's say you have a step that uses the same output type as the tool, you can't now not return the type from the tool anymore because it gets errors because the type is not right.
The docs say
The return type of tool.execute now includes ValidationError to handle validation failures. You must narrow the result type before accessing output schema properties to satisfy TypeScript's type checking.
The return type of tool.execute now includes ValidationError to handle validation failures. You must narrow the result type before accessing output schema properties to satisfy TypeScript's type checking.
but that clearly doesn't work correctly.
e.g. in the code below I get the following error
Property 'fullName' does not exist on type 'ValidationError<any> | { fullName: string; }'.Property 'fullName' does not exist on type 'ValidationError<any>'.ts(2339)
Property 'fullName' does not exist on type 'ValidationError<any> | { fullName: string; }'.Property 'fullName' does not exist on type 'ValidationError<any>'.ts(2339)
because of this the whole createStep is having an error
reproducable code:
import { createStep } from '@mastra/core/workflows';import { z } from 'zod';import { createTool } from '@mastra/core/tools';const fullNameOutputSchema = z.object({ fullName: z.string(),});const fullNameFinderTool = createTool({ id: 'full-name-finder', description: 'Finds a full name', inputSchema: z.object({ firstName: z.string(), }), outputSchema: fullNameOutputSchema, execute: async (inputData) => { return { fullName: `${inputData.firstName} von der Burg`, }; },});export const testStep = createStep({ id: 'test-step', description: 'description', inputSchema: z.object({ firstName: z.string(), }), outputSchema: fullNameOutputSchema, execute: async ({ inputData }) => { const result = await fullNameFinderTool.execute({ firstName: inputData.firstName }); if ('error' in result && result.error) { console.error('Validation failed:', result.message); console.error('Details:', result.validationErrors); return; } return { fullName: result.fullName, }; },});
import { createStep } from '@mastra/core/workflows';import { z } from 'zod';import { createTool } from '@mastra/core/tools';const fullNameOutputSchema = z.object({ fullName: z.string(),});const fullNameFinderTool = createTool({ id: 'full-name-finder', description: 'Finds a full name', inputSchema: z.object({ firstName: z.string(), }), outputSchema: fullNameOutputSchema, execute: async (inputData) => { return { fullName: `${inputData.firstName} von der Burg`, }; },});export const testStep = createStep({ id: 'test-step', description: 'description', inputSchema: z.object({ firstName: z.string(), }), outputSchema: fullNameOutputSchema, execute: async ({ inputData }) => { const result = await fullNameFinderTool.execute({ firstName: inputData.firstName }); if ('error' in result && result.error) { console.error('Validation failed:', result.message); console.error('Details:', result.validationErrors); return; } return { fullName: result.fullName, }; },});