org.llm4s.schema.iron
Members list
Givens
Givens
The uPickle ReadWriter of A :| C: A's, refined after reading. A value that breaks the constraint fails to read with the constraint's message, so completeStructured, completeStructuredOf and Tool.of return a Left naming the field and the bound rather than a value the type should have rejected.
The uPickle ReadWriter of A :| C: A's, refined after reading. A value that breaks the constraint fails to read with the constraint's message, so completeStructured, completeStructuredOf and Tool.of return a Left naming the field and the bound rather than a value the type should have rejected.
Iron's own iron-upickle module defines the same instance: import one of the two, not both, or the instances are ambiguous.
Attributes
The schema of an Iron refinement type, A :| C: the schema of A with C written into it as JSON Schema bounds, so the model is told the bound it must keep.
The schema of an Iron refinement type, A :| C: the schema of A with C written into it as JSON Schema bounds, so the model is told the bound it must keep.
import io.github.iltotore.iron.*
import io.github.iltotore.iron.constraint.all.*
import org.llm4s.schema.*
import org.llm4s.schema.iron.given
case class Review(
@description("Short headline") title: String :| (Not[Blank] & MaxLength[80]),
@description("Stars") rating: Int :| Interval.Closed[1, 5]
) derives SchemaOf, ReadWriter
Described:
- on
Int,Long,DoubleandFloat:Greater,GreaterEqual,Less,LessEqual,StrictEqual,Positive,Positive0,Negative,Negative0and everyInterval, asminimumandmaximum(and, onDoubleandFloat,exclusiveMinimumandexclusiveMaximum). An integer's exclusive bound is written as the inclusive one it equals (Greater[0]asminimum: 1), which every provider accepts. - on
String:MinLength,MaxLength,FixedLength,Not[Empty]andNot[Blank], asminLengthandmaxLength.Not[Blank]is described asminLength: 1, which every non-blank string meets; that the string must not be only whitespace is checked when the reply is read. - on
List,Seq,VectorandSet:MinLength,MaxLength,FixedLengthandNot[Empty], asminItemsandmaxItems. - a conjunction
C1 & C2of these, as both bounds; two bounds of one kind keep the tighter.
Any other constraint, Match among them (core's StringSchema has no pattern yet), and a constraint on any other type, is refused at compile time with a message naming it, rather than left out of the schema without a word.
The bounds are written into the schema A's own SchemaOf builds, so the field keeps its description, and an Option[A :| C], a List[A :| C] or a case class holding one is derived as usual.
Type parameters
- A
-
the refined type
- C
-
the constraint