SafeParameterExtractor

org.llm4s.toolapi.SafeParameterExtractor
See theSafeParameterExtractor companion object
@Stable
final case class SafeParameterExtractor

Safe parameter extraction with type checking and path navigation.

This extractor provides two modes of operation:

  1. Simple mode: Returns Either[String, T] for backward compatibility
  2. Enhanced mode: Returns Either[ToolParameterError, T] for structured error reporting

Value parameters

call

The tool call being run, when the caller knows it: an agent sets it for every call, with the call's id and idempotency key (ToolCallInfo); plain ToolRegistry tool calling leaves it None.

params

The JSON parameters to extract from

Attributes

Companion
object
Graph
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

def getArray(path: String): Either[String, Arr]

Extract a required JSON array parameter from the JSON params.

Extract a required JSON array parameter from the JSON params.

Value parameters

path

Dot-separated path to the parameter

Attributes

Returns

Right(ujson.Arr) on success, Left(errorMessage) on failure

def getArrayEnhanced(path: String): Either[ToolParameterError, Arr]

Extract a required JSON array parameter with structured error reporting.

Extract a required JSON array parameter with structured error reporting.

Value parameters

path

Dot-separated path to the parameter

Attributes

Returns

Right(ujson.Arr) on success, Left(ToolParameterError) on failure

def getBoolean(path: String): Either[String, Boolean]

Extract a required boolean parameter from the JSON params.

Extract a required boolean parameter from the JSON params.

Value parameters

path

Dot-separated path to the parameter

Attributes

Returns

Right(value) on success, Left(errorMessage) on failure

def getBooleanEnhanced(path: String): Either[ToolParameterError, Boolean]

Extract a required boolean parameter with structured error reporting.

Extract a required boolean parameter with structured error reporting.

Value parameters

path

Dot-separated path to the parameter

Attributes

Returns

Right(value) on success, Left(ToolParameterError) on failure

def getDouble(path: String): Either[String, Double]

Extract a required double (number) parameter from the JSON params.

Extract a required double (number) parameter from the JSON params.

A whole number above 2^53 (9007199254740992) has already been rounded to the nearest double when the tool call's arguments were parsed, so it cannot be recovered here. Declare large identifiers as strings in the tool's schema.

Value parameters

path

Dot-separated path to the parameter

Attributes

Returns

Right(value) on success, Left(errorMessage) on failure

def getDoubleEnhanced(path: String): Either[ToolParameterError, Double]

Extract a required double (number) parameter with structured error reporting.

Extract a required double (number) parameter with structured error reporting.

Value parameters

path

Dot-separated path to the parameter

Attributes

Returns

Right(value) on success, Left(ToolParameterError) on failure

def getInt(path: String): Either[String, Int]

Extract a required integer parameter from the JSON params.

Extract a required integer parameter from the JSON params.

JSON numbers reach this class as doubles, so an integer is a number with no fractional part that fits in an Int: 3, 3.0, 1e2 and -0.0 are accepted; 3.14, 2147483648, 1e10 and anything too large are refused as a type mismatch instead of being truncated or wrapped around, so a model that sends one gets an error it can correct.

Value parameters

path

Dot-separated path to the parameter

Attributes

Returns

Right(value) on success, Left(errorMessage) on failure

def getIntEnhanced(path: String): Either[ToolParameterError, Int]

Extract a required integer parameter with structured error reporting.

Extract a required integer parameter with structured error reporting.

Value parameters

path

Dot-separated path to the parameter

Attributes

Returns

Right(value) on success, Left(ToolParameterError) on failure

def getObject(path: String): Either[String, Obj]

Extract a required JSON object parameter from the JSON params.

Extract a required JSON object parameter from the JSON params.

Value parameters

path

Dot-separated path to the parameter

Attributes

Returns

Right(ujson.Obj) on success, Left(errorMessage) on failure

def getObjectEnhanced(path: String): Either[ToolParameterError, Obj]

Extract a required JSON object parameter with structured error reporting.

Extract a required JSON object parameter with structured error reporting.

Value parameters

path

Dot-separated path to the parameter

Attributes

Returns

Right(ujson.Obj) on success, Left(ToolParameterError) on failure

def getOptionalBoolean(path: String): Either[ToolParameterError, Option[Boolean]]

Extract an optional boolean parameter. Returns Right(None) when the parameter is absent.

Extract an optional boolean parameter. Returns Right(None) when the parameter is absent.

Value parameters

path

Dot-separated path to the parameter

Attributes

Returns

Right(Some(value)) if present, Right(None) if absent, Left on type mismatch

def getOptionalDouble(path: String): Either[ToolParameterError, Option[Double]]

Extract an optional double (number) parameter. Returns Right(None) when the parameter is absent.

Extract an optional double (number) parameter. Returns Right(None) when the parameter is absent.

Value parameters

path

Dot-separated path to the parameter

Attributes

Returns

Right(Some(value)) if present, Right(None) if absent, Left on type mismatch

def getOptionalInt(path: String): Either[ToolParameterError, Option[Int]]

Extract an optional integer parameter. Returns Right(None) when the parameter is absent.

Extract an optional integer parameter. Returns Right(None) when the parameter is absent.

Value parameters

path

Dot-separated path to the parameter

Attributes

Returns

Right(Some(value)) if present, Right(None) if absent, Left on type mismatch

def getOptionalString(path: String): Either[ToolParameterError, Option[String]]

Extract an optional string parameter. Returns Right(None) when the parameter is absent.

Extract an optional string parameter. Returns Right(None) when the parameter is absent.

Value parameters

path

Dot-separated path to the parameter

Attributes

Returns

Right(Some(value)) if present, Right(None) if absent, Left on type mismatch

def getString(path: String): Either[String, String]

Extract a required string parameter from the JSON params.

Extract a required string parameter from the JSON params.

Value parameters

path

Dot-separated path to the parameter (e.g., "user.name")

Attributes

Returns

Right(value) on success, Left(errorMessage) if the parameter is absent or not a string

def getStringEnhanced(path: String): Either[ToolParameterError, String]

Extract a required string parameter with structured error reporting.

Extract a required string parameter with structured error reporting.

Value parameters

path

Dot-separated path to the parameter

Attributes

Returns

Right(value) on success, Left(ToolParameterError) on failure

def validateRequired(requirements: (String, String)*): Either[List[ToolParameterError], Unit]

Validate all required parameters at once and collect all errors.

Validate all required parameters at once and collect all errors.

Useful for upfront validation before any business logic runs.

expectedType is one of string, integer, number, boolean, array or object, checked with the same rules as the typed getters (integer is a whole number in the Int range). A type name this method does not know is checked for presence only.

Value parameters

requirements

Pairs of (path, expectedType) to validate

Attributes

Returns

Right(()) if all parameters are present and have the correct types, Left(errors) with the full list of validation failures otherwise

Example
extractor.validateRequired("name" -> "string", "age" -> "integer")

An extractor for the given call.

An extractor for the given call.

Attributes

An extractor for the given call, or for no call.

An extractor for the given call, or for no call.

Attributes

def withParams(params: Value): SafeParameterExtractor

An extractor over other parameters, for the same call.

An extractor over other parameters, for the same call.

Attributes

Inherited methods

def productElementNames: Iterator[String]

Attributes

Inherited from:
Product
def productIterator: Iterator[Any]

Attributes

Inherited from:
Product