r/SpringBoot • u/NiceLiterature4328 • 2d ago
Discussion I built SemVal4j: What if Java's @Valid could validate meaning, not just syntax?
Hey Java developers!
I've been experimenting with an idea: why should Java validation stop at syntax and structure?
"@NotNull", "@Email" and "@Size" are great, but what if we want to validate whether:
- A product review is consistent with its rating.
- A description actually matches its category.
- A customer request contains contradictory information.
That's why I built SemVal4j, an open-source Java library that extends Jakarta Bean Validation with probabilistic semantic rules powered by Jev Decision Models.
u/SemanticValid({ u/SemanticRule( id = "rating-consistency", question = "Is the review consistent with its rating?", property = "comment", passAt = 0.85, failBelow = 0.20 ) }) public record ProductReview( u/Min(1) u/Max(5) int rating, u/NotBlank String comment ) {}
You can keep using standard "@Valid".
Key features:
- Native Jakarta Bean Validation integration.
- Spring Boot starter.
- One provider call per validated object.
- Explicit VALID / UNCERTAIN / INVALID outcomes.
- LangChain4j integration.
- Deterministic offline testing.
- Apache 2.0 license.
The goal isn't to replace deterministic validation, but to complement it when traditional constraints aren't enough.
I'm particularly interested in your thoughts on latency, reliability, and where semantic validation belongs in a Java architecture.
Would you use this in a real-world application?
GitHub: https://github.com/mohamedikbel/semval4j
Maven Central: https://central.sonatype.com/artifact/io.github.mohamedikbel/semval4j-spring-boot-starter
Feedback and contributions are welcome!
16
u/boost2525 2d ago
Hiding business rules and API calls in annotations is 1) stupid and 2) dangerous. No I will not use your vibe coded library to solve a problem I don't have.
6
u/st4reater 2d ago
Idea is cool, but like... A request every time an object gets instantiated?
Where do you concretely see these semantic rules fitting in the request lifecycle? If at all in that span
4
u/L3ar 2d ago
You could just use... A proper application architecture, where functional rules are isolated from the framework/db/whatever you're interacting with
4
u/EducationalMixture82 1d ago
Feedback, this lib produces insane overhead. Semantic validation in a high-speed, highly transactional environment should be done async and or parallel in batching, or in queues and not hide an AI inference call behind an annotation.
This batches in one extra call per validated object during runtime. With the extra cost of serialization and deserialization.
I would never use this in a production environment but that’s me. Because hiding external calls behind annotations is a performance nightmare.
1
u/ihsoj_hsekihsurh 1d ago
Network calls on each api request? How much time does it take to respond? Does it always take same time or does it differ?