SafeParameterExtractor

org.llm4s.toolapi.SafeParameterExtractor
See theSafeParameterExtractor companion object
case class SafeParameterExtractor(params: Value)

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

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.

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.

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.

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")

Inherited methods

def productElementNames: Iterator[String]

Attributes

Inherited from:
Product
def productIterator: Iterator[Any]

Attributes

Inherited from:
Product