Class LLMReadableCheckedException
- All Implemented Interfaces:
LLMReadable, LLMReadableException, Serializable
- Direct Known Subclasses:
CorrectableLLMException, UncorrectableLLMException
This is the mandatory throws type for all LLM-facing code. Tool.execute(JobResources, JobContext)
declares throws LLMReadableCheckedException, which means every tool, thinker, and doer must
express errors through this hierarchy. Raw exceptions (IOException, SQLException)
cannot escape - they must be wrapped via unwrap(Throwable) or
wrapWithContext(Throwable, String, String, Object, String).
The two branches define LLM behavior:
CorrectableLLMException- The LLM's input was wrong. It may fix its parameters and call the same tool again.UncorrectableLLMException- The tool itself cannot work right now, regardless of input. The LLM should not retry this tool - instead it should try a different tool, take an alternative approach, or explain the limitation to the user.
Subclasses should provide clear, actionable error messages that:
- Explain what went wrong in plain language
- Indicate which parameter or input caused the problem
- Suggest how to fix the issue (valid ranges, formats, etc.)
- Avoid technical jargon that LLMs might not understand in context
Design Philosophy:
- Full exception hierarchy (stack traces, causes) preserved for developer debugging
- Clean, LLM-friendly messages extracted via
getLLMMessage() - Formatted output for conversation via
explainToLLM() - No automatic retries - LLM decides all next steps based on error information
IMPORTANT: Do NOT create service-specific exception hierarchies.
NEVER create classes like FooException extends LLMReadableException for a service.
NEVER create FooAuthException, FooInvalidInputException, FooServerException, etc.
The framework already provides the right concrete types via CorrectableLLMException and
UncorrectableLLMException. Every external service should map its HTTP error codes directly
to the existing framework types:
- HTTP 400/422 ->
InvalidInputException - HTTP 401/403 ->
UnauthorizedException - HTTP 404 (fetch-by-ID) ->
ResourceNotFoundException - HTTP 413 ->
InvalidInputException(file too large = correctable) - HTTP 429 ->
Http429Exception, anUpstreamThrottleException(rate limit) - HTTP 500+ and any other error status ->
ExternalServiceException(server error) - Network errors ->
ExternalServiceException(connection/timeout)
HttpExceptions performs that mapping for
every status; a client never spells it out.
The hierarchy:
LLMReadable (marker interface)
+-- LLMReadableException (sealed, extends LLMReadable)
+-- LLMReadableCheckedException (sealed, checked)
| +-- CorrectableLLMException (non-sealed abstract, isCorrectable=true)
| | +-- InvalidInputException, ResourceNotFoundException, GuardrailException, ...
| +-- UncorrectableLLMException (non-sealed abstract, isCorrectable=false)
| +-- ExternalServiceException, UnauthorizedException, SystemException, ...
+-- LLMReadableRuntimeException (sealed, unchecked)
+-- CorrectableRuntimeLLMException (non-sealed concrete, isCorrectable=true)
+-- UncorrectableRuntimeLLMException (non-sealed concrete, isCorrectable=false)
- Since:
- 0.1 (2026-03-29)
- Author:
- Andrey Santrosyan
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionLLMReadableCheckedException(String message) Constructs a new LLM-readable exception with the specified detail message.LLMReadableCheckedException(String message, Throwable cause) Constructs a new LLM-readable exception with the specified detail message and cause. -
Method Summary
Modifier and TypeMethodDescriptionReturns a fully formatted string to add to the LLM conversation context.abstract StringReturns a clean, actionable error message suitable for LLM understanding.abstract booleanIndicates whether the LLM may retry the same tool with different input.static LLMReadableCheckedExceptionUnwraps a throwable to find a buriedLLMReadableExceptionexception, or wraps it in aSystemExceptionif none is found.static LLMReadableCheckedExceptionwrapWithContext(Throwable t, String serviceName, String paramName, Object paramValue, String operation) Wraps a throwable with semantic context, preserving the correctable/uncorrectable distinction.Methods inherited from class Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Constructor Details
-
LLMReadableCheckedException
Constructs a new LLM-readable exception with the specified detail message.- Parameters:
message- the detail message (for logging and debugging)
-
LLMReadableCheckedException
Constructs a new LLM-readable exception with the specified detail message and cause.The cause is preserved for developer debugging while the LLM message is extracted from the subclass implementation.
- Parameters:
message- the detail message (for logging and debugging)cause- the cause (which is saved for later retrieval byThrowable.getCause())
-
-
Method Details
-
getLLMMessage
Returns a clean, actionable error message suitable for LLM understanding.This message should:
- Explain what went wrong in plain language
- Be specific about which parameter or input caused the problem
- Suggest how to fix the issue when possible
- Avoid stack traces, exception types, or code references
Good examples:
- "Maximum result limit is 100. Please reduce maxResults parameter to 100 or less."
- "Parameter 'dateFrom' has invalid format '2024-13-01'. Use ISO 8601 format: YYYY-MM-DD."
- "Permission denied to access system clock. This tool requires elevated privileges."
Bad examples:
- "NullPointerException at line 247"
- "Error code -1"
- "Invalid input" (not specific enough)
- Specified by:
getLLMMessagein interfaceLLMReadable- Returns:
- clean, actionable error message for LLM
-
explainToLLM
Returns a fully formatted string to add to the LLM conversation context.This declaration restates the interface default: just the LLM message. The four branch classes,
CorrectableLLMException,UncorrectableLLMException,CorrectableRuntimeLLMExceptionandUncorrectableRuntimeLLMException, override it to append their correctability hint, and no concrete class overrides it again, so every exception tells the model whether to retry in the same words.- Specified by:
explainToLLMin interfaceLLMReadableException- Returns:
- formatted string for conversation context
-
isCorrectable
public abstract boolean isCorrectable()Indicates whether the LLM may retry the same tool with different input.true (correctable): The LLM's input was wrong. It may fix its parameters and call the same tool again, or take a different approach if correction seems unlikely to help. Examples: invalid query syntax, missing required field, malformed identifier, ID that doesn't exist.
false (uncorrectable): The tool itself cannot work right now, regardless of what the LLM sends. No amount of parameter tweaking will help. The LLM should not retry this tool - instead it should try a different tool, take an alternative approach, or explain the limitation to the user. Examples: API down, auth failure, rate limit, system error.
- Specified by:
isCorrectablein interfaceLLMReadableException- Returns:
- true if the LLM should retry the same tool with corrected input, false if the LLM should abandon this tool and try something else
-
wrapWithContext
public static LLMReadableCheckedException wrapWithContext(Throwable t, String serviceName, String paramName, Object paramValue, String operation) Wraps a throwable with semantic context, preserving the correctable/uncorrectable distinction.Use this in multi-step tools where the LLM needs to know which step failed and why. Catches the throwable and call this method to produce a properly typed exception:
CorrectableLLMException(e.g., HTTP 400) becomesInvalidInputExceptionwith the caller's parameter name, so the LLM knows which input to fixUncorrectableLLMException(e.g., HTTP 500, auth failure) becomesExternalServiceExceptionwith the operation context- Any other throwable becomes
ExternalServiceException
A live retry signal in the chain is rethrown instead, as
unwrap(Throwable)does and by the same rule.Example:
try { response = apiUtil.get(path); } catch (Throwable t) { throw LLMReadableCheckedException.wrapWithContext(t, "PubChem", "compoundIdentifier", identifier, "CID resolution for " + idType); }- Parameters:
t- the original throwableserviceName- the external service name (e.g., "PubChem", "ChEMBL")paramName- the LLM-facing parameter that triggered this operationparamValue- the value the LLM provided for that parameteroperation- description of what was being attempted- Returns:
- an LLMReadableException with context, ready to throw
-
unwrap
Unwraps a throwable to find a buriedLLMReadableExceptionexception, or wraps it in aSystemExceptionif none is found.Use this when code must only throw
LLMReadableCheckedExceptionbut calls methods that throw broader exceptions (e.g.,ExecutionExceptionfromJobHandle.get(), orInterruptedException).Walks the cause chain to the first exception that decides the outcome: a dispatcher retry signal or an LLM-readable exception, whichever comes first. A checked
LLMReadableCheckedExceptionis returned. A runtimeLLMReadableRuntimeExceptionis thrown as itself, keeping its correctable/uncorrectable classification. A chain with neither becomes aSystemException.Retry signals. A dispatcher retry signal - every
UpstreamRetryException, and the dispatcher's ownResponseCorrectionRetryExceptionandOutputTruncationRetryException- is rethrown as itself when nothing LLM-readable lies above it in the chain, so a broad catch around a job's own model exchange hands the signal to that job's dispatcher loop and never turns a wait the dispatcher knows how to do into a failure. A signal that lies beneath an LLM-readable exception is not rethrown: whoever built that exception held the signal and ruled on it. That is how a child job's failure arrives, its retries spent, its time budget or its cancellation reached, and it travels up as the failure it is, with the signal still readable in its cause chain. The job that awaits the child runs once.All call sites use
throw LLMReadableCheckedException.unwrap(e), so every path exits with the correct exception type.- Parameters:
t- the throwable to unwrap- Returns:
- an LLMReadableException - either the original buried one, or a new SystemException
- Throws:
LLMReadableRuntimeException- if a runtime LLM-readable exception is found in the chain
-