Help with using Structured Outputs for JSON Patch Generation and Handling the "value" Field in JSON Schema

Hi everyone,

I’m working on generating JSON Patch operations using Structured Outputs, and I’m running into an issue with defining the value field in my JSON Schema. As you know, the value field in a JSON Patch operation can be of various types: string, number, array, or object.

The problem arises when I’m trying to define the schema for this value field. Since it can hold different types, I’m not sure how to properly describe it in the schema so that it supports all possible types (string, number, array, object, etc.).

  1. How should I define the value field in JSON Schema to make it flexible enough to handle these cases?
  2. Is there a way to give AI some guidance on how to properly structure the JSON Patch operations? Specifically, I’d like to make sure that the op values (add, replace, remove, etc.) and path are correctly formatted and validated, and that the value field, when required, is assigned correctly based on the operation type.

I would greatly appreciate any insights or examples you can provide! Thanks in advance!

2 Likes