Class SchemaGenerator

java.lang.Object
com.axelor.ai.tool.system.SchemaGenerator

public class SchemaGenerator extends Object
Generates a LangChain4j JsonObjectSchema from a Java record class and its Param annotations.
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    canBeClosed(dev.langchain4j.model.chat.request.json.JsonObjectSchema schema)
    Whether this schema is one a provider can be asked to hold the model to.
    static dev.langchain4j.model.chat.request.json.JsonObjectSchema
    fromRecord(Class<? extends Record> recordClass)
     
    static boolean
    hasOptionalEnum(dev.langchain4j.model.chat.request.json.JsonObjectSchema schema)
    Whether an enum in this schema is optional.
    static boolean
    isTrivial(dev.langchain4j.model.chat.request.json.JsonObjectSchema schema)
    Whether this schema is at most one scalar that is not an enum: closing it constrains nothing the parameter's own type does not already say.
    static int
    optionalCount(dev.langchain4j.model.chat.request.json.JsonSchemaElement element)
    The parameters, at any depth, that are not required: what a provider counts when it limits the optional parameters of a request's strict schemas.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • fromRecord

      public static dev.langchain4j.model.chat.request.json.JsonObjectSchema fromRecord(Class<? extends Record> recordClass)
    • canBeClosed

      public static boolean canBeClosed(dev.langchain4j.model.chat.request.json.JsonObjectSchema schema)
      Whether this schema is one a provider can be asked to hold the model to.

      Two things decide it. Every object must say which properties it has: closing an object that does not — a free-form map, whose keys are the caller's data — would forbid the very keys it exists to carry, and the tool would be unusable. And no value may be a union.

      The union rule is caution rather than necessity. A union carries its own null, so an optional one survives the rewrite that closing a schema performs, and it ought to be accepted; but that is a claim about a provider's sampler, and the cost of being wrong is every call of that tool failing at the provider rather than a value being refused here. It is worth lifting once it has been watched working against a live one.

    • hasOptionalEnum

      public static boolean hasOptionalEnum(dev.langchain4j.model.chat.request.json.JsonObjectSchema schema)
      Whether an enum in this schema is optional. Closing a schema makes every optional property nullable, ["string", "null"], but leaves an enum's values as they were, without null: OpenAI accepts that, while Anthropic refuses the request outright, whatever tool the model was about to call.
    • isTrivial

      public static boolean isTrivial(dev.langchain4j.model.chat.request.json.JsonObjectSchema schema)
      Whether this schema is at most one scalar that is not an enum: closing it constrains nothing the parameter's own type does not already say.
    • optionalCount

      public static int optionalCount(dev.langchain4j.model.chat.request.json.JsonSchemaElement element)
      The parameters, at any depth, that are not required: what a provider counts when it limits the optional parameters of a request's strict schemas.