llm-json-fix
Version:
Fix malformed JSON outputs from Large Language Models (LLMs)
47 lines (46 loc) • 1.37 kB
JavaScript
/**
* Custom error thrown by the LLM JSON Fix library
*/
export class LLMJSONFixError extends Error {
/**
* Create a new LLMJSONFixError
* @param message The error message
* @param position The position in the text where the error occurred (if available)
*/
constructor(message, position) {
super(message);
this.position = position;
this.name = 'LLMJSONFixError';
// Maintain proper stack trace in V8 engines
if (Error.captureStackTrace) {
Error.captureStackTrace(this, LLMJSONFixError);
}
}
}
/**
* Error thrown when a repair operation could not be completed
*/
export class UnrepairableJSONError extends LLMJSONFixError {
constructor(message, position) {
super(message, position);
this.name = 'UnrepairableJSONError';
}
}
/**
* Error thrown when the input JSON is too complex or ambiguous to be repaired
*/
export class AmbiguousRepairError extends LLMJSONFixError {
constructor(message, position) {
super(message, position);
this.name = 'AmbiguousRepairError';
}
}
/**
* Error thrown when repair operation exceeds buffer limits
*/
export class BufferLimitExceededError extends LLMJSONFixError {
constructor(message, position) {
super(message, position);
this.name = 'BufferLimitExceededError';
}
}