Skip to content

ThinkLang Error Catalog

ThinkLang produces two categories of errors: runtime errors (thrown during execution) and static errors (reported during type checking/parsing).


Runtime Errors

All runtime errors extend ThinkError, which extends the built-in JavaScript Error. They can be caught in ThinkLang using try/catch blocks.

ThinkError

Base class for all ThinkLang runtime errors. Not typically thrown directly.

PropertyTypeDescription
namestring"ThinkError"
messagestringError description

SchemaViolation

Thrown when the LLM output does not match the expected JSON Schema.

PropertyTypeDescription
namestring"SchemaViolation"
expectedstringDescription of the expected type
gotunknownThe actual value received from the LLM

Message format: Schema violation: expected <expected>, got <got>

Common causes:

  • The LLM returned a string when an object was expected
  • A required field is missing from the output
  • A field has the wrong type (e.g., string instead of number)

ThinkLang catch syntax:

thinklang
try {
  let result = think<MyType>("prompt")
} catch SchemaViolation (e) {
  print "Schema mismatch"
}

ConfidenceTooLow

Thrown when calling .unwrap(threshold) or .expect(threshold) on a Confident<T> value whose confidence falls below the specified threshold.

PropertyTypeDescription
namestring"ConfidenceTooLow"
thresholdnumberThe required minimum confidence
actualnumberThe actual confidence value

Message format: Confidence too low: expected >= <threshold>, got <actual>

Common causes:

  • Calling .expect(0.9) on a result with confidence 0.6
  • Calling .unwrap(0.5) when the model is uncertain
  • Ambiguous input that the model cannot classify with high confidence

ThinkLang catch syntax:

thinklang
try {
  let value = result.expect(0.9)
} catch ConfidenceTooLow (e) {
  print "Model was not confident enough"
}

GuardFailed

Thrown when a guard rule constraint is violated.

PropertyTypeDescription
namestring"GuardFailed"
guardNamestringName of the failed guard rule (e.g., "length", "contains_none")
guardValueunknownThe actual value that failed validation
constraintstringDescription of the constraint (e.g., "5..500")

Message format: Guard '<guardName>' failed: <constraint> (got <value>)

Common causes:

  • Output text is too short or too long for a length guard
  • Output contains a forbidden term checked by contains_none
  • A custom passes validator returned false or threw an error
  • A numeric value fell outside a range guard

ThinkLang catch syntax:

thinklang
try {
  let result = think<Translation>("Translate")
    with context: text
    guard { length: 10..500 }
} catch GuardFailed (e) {
  print "Guard validation failed"
}

Mitigation: Use on_fail: retry(n) to automatically retry when guards fail:

thinklang
let result = think<Translation>("Translate")
  with context: text
  guard { length: 10..500 }
  on_fail: retry(3)

TokenBudgetExceeded

Thrown when an operation exceeds the configured token budget.

PropertyTypeDescription
namestring"TokenBudgetExceeded"
budgetnumberThe configured token budget
requirednumberThe number of tokens actually needed

Message format: Token budget exceeded: budget=<budget>, required=<required>

Common causes:

  • Very large context data exceeding the token limit
  • Extremely detailed prompts combined with large schemas

ModelUnavailable

Thrown when the specified model cannot be reached or is not available.

PropertyTypeDescription
namestring"ModelUnavailable"
modelstringThe model identifier that was requested

Message format: Model unavailable: <model>

Common causes:

  • Invalid model name in THINKLANG_MODEL
  • Anthropic API outage
  • Model deprecated or not yet available

Timeout

Thrown when an operation exceeds its time limit.

PropertyTypeDescription
namestring"Timeout"
durationMsnumberThe duration in milliseconds before timeout

Message format: Operation timed out after <durationMs>ms

Common causes:

  • Slow network connection to the Anthropic API
  • Very large prompts requiring long processing time

Error Hierarchy

Error
  └── ThinkError
        ├── SchemaViolation
        ├── ConfidenceTooLow
        ├── GuardFailed
        ├── TokenBudgetExceeded
        ├── ModelUnavailable
        └── Timeout

Parse Errors

Parse errors occur when the source code does not conform to the ThinkLang grammar. These are reported at compile time and prevent execution.

Common parse error causes:

CauseExample
Missing closing bracetype Foo { name: string
Invalid type expressionlet x: unknownPrimitive = ...
Missing expression after =let x =
Unterminated stringlet x = "hello
Invalid guard syntaxguard { length 5 } (missing : and range)
Missing parentheses in thinkthink<string> "prompt"

Parse errors include location information (line and column) when available.


Type Check Errors

Type check errors are reported by the checker during compilation. They are instances of CheckDiagnostic and include a severity ("error" or "warning") and optional source location.

UncertainAccessError

Severity: error

Raised when code attempts to access a property on an uncertain variable without first unwrapping it.

PropertyTypeDescription
messagestringError description
locationLocation?Source location

Message format: Cannot access property on uncertain value '<name>'. Use .unwrap(), .expect(threshold), or .or(fallback) first.

Example of invalid code:

thinklang
let uncertain result = think<Category>("Classify")
  with context: text
// Error: cannot access .name on uncertain value
print result.name

Fix:

thinklang
let uncertain result = think<Category>("Classify")
  with context: text
let safe = result.unwrap()
print safe.name

TypeMismatchError

Severity: error

Raised when an expression's type does not match the expected type.

PropertyTypeDescription
messagestringError description
locationLocation?Source location

Message format: Type mismatch: expected <expected>, got <got>


UndefinedVariableError

Severity: error

Raised when code references a variable that has not been declared.

PropertyTypeDescription
messagestringError description
locationLocation?Source location

Message format: Undefined variable '<name>'

Example:

thinklang
// Error: 'data' is not defined
print data.field

UndefinedTypeError

Severity: error

Raised when code references a type name that has not been declared.

PropertyTypeDescription
messagestringError description
locationLocation?Source location

Message format: Undefined type '<name>'

Example:

thinklang
// Error: type 'UnknownType' is not defined
let result = think<UnknownType>("prompt")

NonExhaustiveMatchWarning

Severity: warning

Raised when a match expression may not cover all possible cases.

PropertyTypeDescription
messagestringWarning description
locationLocation?Source location

Message format: Match expression may not be exhaustive. Consider adding a wildcard (_) arm.

Example of code that triggers this warning:

thinklang
let response = match sentiment {
  { confidence: >= 0.9 } => "High"
  { confidence: >= 0.5 } => "Medium"
  // Warning: no wildcard arm for values below 0.5
}

Fix:

thinklang
let response = match sentiment {
  { confidence: >= 0.9 } => "High"
  { confidence: >= 0.5 } => "Medium"
  _ => "Low"
}

Error Summary Table

ErrorCategorySeverityCatchable at runtime
SchemaViolationRuntimeErrorYes
ConfidenceTooLowRuntimeErrorYes
GuardFailedRuntimeErrorYes
TokenBudgetExceededRuntimeErrorYes
ModelUnavailableRuntimeErrorYes
TimeoutRuntimeErrorYes
Parse errorCompile-timeErrorNo
UncertainAccessErrorType checkErrorNo
TypeMismatchErrorType checkErrorNo
UndefinedVariableErrorType checkErrorNo
UndefinedTypeErrorType checkErrorNo
NonExhaustiveMatchWarningType checkWarningNo