Effect CommunityEC
Effect Community2mo ago
8 replies
Lloyd

Possible Bug with Recursive Schema in `Toolkit` or `JSONSchema`

I think i found a bug with Toolkit or in JSONSchema. I have a very complicated recursive schema to represent a HAST and when calling it as an input to a tool, I get an error. With a minimal setup like so:
const echoTool = Tool.make("echo", {
  description:
    "Echo back a message. Useful for testing tool calling. Example: echo(message: 'Hello, World!')",
  parameters: {
    input: GenericElement, // <- Very complicated Schema
  },
});

export const SampleToolkit = Toolkit.make(echoTool);

export const SampleToolkitLive = SampleToolkit.toLayer({
  echo: (params: { input }) =>
    Effect.gen(function* () {
      yield* Effect.log(`Echo: ${params.input}`);
      return yield* Effect.succeed(`Echo: ${params.input.type}`);
    }),
 });

// Calling model results in: Response Body: { "error": { "message": "Invalid schema for function 'echo': In context=('anyOf', '2'), 'required' is required to be supplied and to be an array including every key in properties. Missing 'slot'.", "type": "invalid_request_error", "param": "tools[3].parameters", "code": "invalid_function_parameters" } }


Can find the code for the GenericElement here -> https://effect.website/play/#902a397da008

From the error it looks like the issue is with the Schema.optional in the ElementBase but since everything else looks fine and its only OpenAI complaining about it I thought this might be something wrong with either the Toolkit or the JSONSchema implementations. Will add the output from JSONSchema.make in the thread:
Was this page helpful?