Skip to content

Q: Dynamic structured outputs #577

@eneroth

Description

@eneroth

I use this SDK from Clojure, and I have the need to use dynamic schemas, generated at runtime based on user interactions. Both of these factors make it difficult for me to follow the recommended path of declaring static classes to express the schema. The more straightforward path is to generate a JSON schema as a string, and then use that.

The workaround I have found is to putAdditionalBodyProperty, like so:

(.putAdditionalBodyProperty builder "text"
  (JsonValue/from 
    {"format" {"type"   "json_schema"
               "name"   "pick_some_numbers"
               "strict" true
               "schema" {"properties"           {"picked-numbers" {"items" {"type" "number"}, "type" "array"},
                                                 "motivation"     {"type" "string", "description" "Explain why you chose these numbers"}},
                         "required"             ["picked-numbers" "motivation"],
                         "type"                 "object",
                         "additionalProperties" false}}}))

Sorry for the Clojure. The above is just an example.

This appears to give me the the JSON as a string in a ResponseOutputText object, which I can then transform given that I know that I gave it the instruction to return a structured output.

My question is: Is this the least unsupported option available to me, or is there a better option that you would recommend?

Many thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requestedsdk

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions