Proposal: StructuredDecisionModel, an experimental abstraction for typed batch decisions
Summary
Implementation: core PR #6469 and TypeSafe community PR #797. The name StructuredDecisionModel was agreed in the naming discussion.
I'd like to propose a new experimental model abstraction in the standalone langchain4j-experimental-structured-decision module: a StructuredDecisionModel that evaluates a state against a batch of typed, named questions in a single call, returning structured answers with calibrated confidence. ChatModel, ScoringModel and ModerationModel do not cover this today.
The immediate driver is TypeSafe AI's System One API and its model Jev (docs, announcement), but the abstraction is provider-neutral: structured decision APIs can implement it natively, and any ChatModel with structured outputs can emulate it. OpenAI's Classifications API points the same direction.
Background: what a "System One" / structured decision API is
TypeSafe's System One is not a chat model: there is no conversation, no tool calling, no streaming. In a single request you provide:
state: text or JSON-like map/list contextquestions: a map of named, typed questions, evaluated in parallelmodel: the model to use (e.g.jev-latest)
Each question is one of three primitives:
| Primitive | Returns | Example |
|---|---|---|
noul |
a probability 0..1 for a boolean-style judgment |
answers["refund_requested"].noul >= 0.7 |
choice |
one option out of a named set | routing an email to billing / support / sales |
score |
a graded value on named levels | customer frustration level |
The SDKs model criteria as structured, contrastive fields (what, not_for, examples) on options and levels, and the wire format accepts arbitrary structured descriptions. Choice and score answers carry a calibrated confidence; a noul answer is itself a probability. TypeSafe's claims for this model class: schema-constrained output, ~100ms latency, self-consistent repeated answers, and roughly two orders of magnitude faster and cheaper than frontier chat models for these tasks.
Why the existing interfaces don't cover this
| Interface | What it does | What's missing for typed decisions |
|---|---|---|
ChatModel |
conversation, tools, streaming | one "question" per call, no calibrated confidence, criteria become prompt strings |
ScoringModel |
scoreAll(texts, query) → List<Double> |
single dimension (relevance vs a query), no named heterogeneous questions, no choices, no confidence |
ModerationModel |
fixed safety taxonomy | questions are user-defined, not a fixed set; no scores/confidence |
Today this kind of classification, gating or LLM-as-judge check gets built by hand over ChatModel and structured outputs: N sequential calls, no confidence semantics, prompts instead of typed criteria.
Why this matters for enterprise environments
- Auditability: answers are typed and schema-constrained (no free text), so every automated decision can be logged with its question, value and confidence, and reviewed later, which is what compliance and audit workflows expect.
- Measurable escalation: calibrated confidence turns "when do we involve a human" into an explicit, measurable threshold instead of a prompt heuristic, a common requirement in regulated processes (claims triage, KYC/AML, content policy).
- Policy as data: criteria (
what,not_for,examples) are typed and versionable, so risk and domain teams can review what the system classifies on without reading prompts buried in code. - Inline throughput: decisions in ~100ms make checks practical inside high-volume pipelines (document processing, routing, filtering), at a predictable per-call cost.
Proposed design (sketch)
public interface StructuredDecisionModel {
StructuredDecisionResponse decide(StructuredDecisionRequest request);
// async hook, mirroring the ScoringModel#doScoreAsync pattern (1.20.0)
default CompletableFuture<StructuredDecisionResponse> decideAsync(StructuredDecisionRequest request) { ... }
default StructuredDecisionRequestParameters defaultRequestParameters() { ... }
}
// request
StructuredDecisionRequest.builder()
.state(state) // nested context (Map<String, Object> / typed state)
.question("refund_requested", NoulQuestion.builder()
.criteria(NoulCriteria.builder().what("...").notFor("...").examples(...).build())
.build())
.question("team", ChoiceQuestion.builder()
.option("billing", OptionCriteria.builder().what("...").notFor("...").build())
.option("support", ...)
.build())
.question("frustration", ScoreQuestion.builder()
.level("low", ...).level("medium", ...).level("high", ...)
.build())
.build();
// response: Map<String, StructuredDecisionAnswer> keyed by question name
answer.choice(); // String — chosen option
answer.noul(); // Double — probability
answer.score(); // Double — numeric score
answer.confidence(); // Double — calibrated confidence- Sealed interface
QuestionwithNoulQuestion,ChoiceQuestion,ScoreQuestion. - Everything under
dev.langchain4j.model.structureddecisionin the standalone experimental module, annotated@Experimental. Requests can carry optionalList<Content>, per-call additional properties, and responses expose generic metadata. - Follows the established request/response + parameters + async pattern of the 1.20.0-era
ScoringModel/EmbeddingModelAPIs.
Integration plan
Per the contributing guidelines, the provider module would live in the community repo:
- New module
models/langchain4j-community-typesafe, withTypeSafeStructuredDecisionModel implements StructuredDecisionModel. - No official Java SDK exists, so the client is implemented directly with
langchain4j-http-client+ Jackson (per CONTRIBUTING), with package-private DTOs mirroring the System One REST API. - Unit tests with a mocked HTTP layer; ITs gated behind an API key.
- A separate follow-up PR could add a
ChatModel-backedStructuredDecisionModel, so any chat model can serve as a fallback where no structured decision API is available.
Relationship to existing abstractions
ModerationModelis conceptually a fixed-taxonomy special case of this pattern; no migration is proposed.ScoringModelstays untouched; relevance and rerank semantics are well established on their own.
Open questions for maintainers
- Naming: resolved as
StructuredDecisionModelin the discussion linked above. - Placement: resolved as a standalone experimental module after review.
- v1 scope: all three primitives (
noul/choice/score), or start from a subset? - Java 17 compatibility and no new core dependencies: the sketch fits both.
Motivation summary
- Provider neutrality: program against the interface, and switch from a native structured decision API (Jev) to a
ChatModelemulation without touching application code. - First-class confidence: enables confidence-gated routing (escalate to a human or a reasoning model below a threshold).
- Heterogeneous questions in one round-trip: composite decisions (spam detection split into six signals) in a single call.
- Declarative criteria instead of prompt strings: typed, versionable, testable.
- Fits existing components: guardrails, agentic routing (a supervisor choosing between agents is a
choice), RAG filtering beyond relevance. - Enterprise fit: auditable typed decisions, measurable escalation thresholds, classification policy as reviewable data.
The abstraction and TypeSafe implementation are available in the linked core and community PRs. I'm happy to rework any of it based on maintainer feedback, starting with the open questions above.
Source: langchain4j/langchain4j