Package com.axelor.ai.tool.system
Class SchemaGenerator
java.lang.Object
com.axelor.ai.tool.system.SchemaGenerator
Generates a LangChain4j
JsonObjectSchema from a Java record class and its Param
annotations.-
Method Summary
Modifier and TypeMethodDescriptionstatic booleancanBeClosed(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.JsonObjectSchemafromRecord(Class<? extends Record> recordClass) static booleanhasOptionalEnum(dev.langchain4j.model.chat.request.json.JsonObjectSchema schema) Whether an enum in this schema is optional.static booleanisTrivial(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 intoptionalCount(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.
-
Method Details
-
fromRecord
-
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, withoutnull: 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.
-