MartinB
MartinB2mo ago

Invalid schema for tool in convex agent.

I migrated away from ai sdk to using the agent from convex however as soon as I add any tools it throws an error. I've checked and can't seem to find an issue with my code. Please help. error:
responseBody: '{\n "error": {\n "message": "Invalid schema for function \'getUserPreferences\': schema must be a JSON Schema of \'type: \\"object\\"\', got \'type: \\"string\\"\'.",\n "type": "invalid_request_error",\n "param": "tools[0].function.parameters",\n "code": "invalid_function_parameters"\n }\n}', isRetryable: false, data: {
error: {
message: 'Invalid schema for function \'getUserPreferences\': schema must be a JSON Schema of \'type: "object"\', got \'type: "string"\'.',
type: 'invalid_request_error',
param: 'tools[0].function.parameters',
code: 'invalid_function_parameters'
}
responseBody: '{\n "error": {\n "message": "Invalid schema for function \'getUserPreferences\': schema must be a JSON Schema of \'type: \\"object\\"\', got \'type: \\"string\\"\'.",\n "type": "invalid_request_error",\n "param": "tools[0].function.parameters",\n "code": "invalid_function_parameters"\n }\n}', isRetryable: false, data: {
error: {
message: 'Invalid schema for function \'getUserPreferences\': schema must be a JSON Schema of \'type: "object"\', got \'type: "string"\'.',
type: 'invalid_request_error',
param: 'tools[0].function.parameters',
code: 'invalid_function_parameters'
}
"dependencies": {
"@ai-sdk/openai": "^1.3.23",
"@convex-dev/agent": "^0.1.15",
"ai": "^4.3.19",
"convex": "^1.25.4",
"convex-helpers": "^0.1.96",
"date-fns": "^4.1.0",
"openai": "^5.9.0"
},
"dependencies": {
"@ai-sdk/openai": "^1.3.23",
"@convex-dev/agent": "^0.1.15",
"ai": "^4.3.19",
"convex": "^1.25.4",
"convex-helpers": "^0.1.96",
"date-fns": "^4.1.0",
"openai": "^5.9.0"
},
import { openai } from "@ai-sdk/openai";
import { Agent } from "@convex-dev/agent";
import { components } from "../convex/_generated/api";
import { z } from "zod";
import { tool } from "ai";

export const assistantAgent = new Agent(components.agent, {
chat: openai("gpt-4.1-nano-2025-04-14"),
instructions: `You are a helpful assistant`,
tools: {
getUserPreferences: tool({
description: "Get clothing preferences for a user",
parameters: z.object({
search: z.string().describe("Which preferences are requested"),
}),
execute: async (args) => {
console.log("getting user preferences", args);
return {
information: `The user likes to look stylish`,
};
},
}),
},
});
import { openai } from "@ai-sdk/openai";
import { Agent } from "@convex-dev/agent";
import { components } from "../convex/_generated/api";
import { z } from "zod";
import { tool } from "ai";

export const assistantAgent = new Agent(components.agent, {
chat: openai("gpt-4.1-nano-2025-04-14"),
instructions: `You are a helpful assistant`,
tools: {
getUserPreferences: tool({
description: "Get clothing preferences for a user",
parameters: z.object({
search: z.string().describe("Which preferences are requested"),
}),
execute: async (args) => {
console.log("getting user preferences", args);
return {
information: `The user likes to look stylish`,
};
},
}),
},
});
1 Reply
Convex Bot
Convex Bot2mo ago
Thanks for posting in <#1088161997662724167>. Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets. - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.) - Use search.convex.dev to search Docs, Stack, and Discord all at once. - Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI. - Avoid tagging staff unless specifically instructed. Thank you!

Did you find this page helpful?