spring-projects / spring-projects/spring-ai
Generate complex Json schemas with BeanOutputConverter
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 9.5k
- Forks
- 2.9k
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 6
Description
Expected Behavior
Be able to generate more complex schemas with the BeanOutputConverter class, for instance with constrains definitions like max elements in array and max or min length for strings. This can be handled adding support to the definition of what modules should be loaded for jsonschema-generator library. Could be allowing override the private method generateSchema or adding it as a constructor parameter.
Current Behavior
Right now the BeanOutputConverter is adding just the jackson-module to the configuration of jsonschema-generator library, this is a great starting point to have a schema definition but does not allow the definition of more complex scenarios. The code to generate the value for jsonSchema field is private so we cannot override it to adding more modules to the libray.
Context
Under some circumstances we can ask to the AI model to generate content with specific rules, for instance if we want to generate specific number of answers for one question. In that case we can specify it with the prompt but probably could be a good idea add it as a constraint to the expected schema just to be sure the AI model respect it. This can be handled with the maven library jsonschema-module-jakarta-validation. I tested locally and just add it to the jsonschema-generator library configuration it's enough to add constraints to the generated schema.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the BeanOutputConverter class and its private generateSchema method, then inspect how jsonschema-generator is configured with the Jackson module. Determine how additional schema modules such as jsonschema-module-jakarta-validation can be supplied, and verify that constraints like array bounds and string lengths appear in the generated schema.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100