Skip to main content
Sometimes you need a single value — a number, a string, a boolean — without the overhead of defining a dedicated response class. The Scalar adapter handles this by wrapping a single typed field in a minimal schema.

Basic Usage

The first argument to each factory method is the field name, which gives the model semantic context about what value to extract. An optional second argument provides a description for additional guidance.

Available Types

String

Integer

Float

Boolean

Enum

Use Scalar::enum() to select one value from a backed enum:
The model sees the enum’s backed values as the allowed options and returns one of them. Instructor deserializes it back into the enum instance.

Factory Method Signatures

All factory methods accept the same optional parameters:

Typed Convenience Methods

When you are already working with a StructuredOutput or PendingStructuredOutput instance, you can skip get() and call a typed accessor that validates the return type:
Available typed methods: getString(), getInt(), getFloat(), getBoolean(). These methods throw an exception if the result is not of the expected type, which provides an extra safety check beyond what get() offers.