Zouabi
01/15/2026, 8:54 AMerror.prompt.
2. Can message be split into errors instead of combine multiple things? Especially a way to get the LLM Client JSON response and then a way to get BAML error message by itself.
Code snippet:
ts
try {
const stream = b.stream.Generate(..., { signal });
for await (const chunk of stream)
yield chunk;
const final = await stream.getFinalResponse();
yield final;
} catch (error) {
if (signal.aborted) return console.debug("Generation aborted");
if (error instanceof BamlValidationError) {
const until = error.message.indexOf(" - LLM client");
const message = error.message.slice(
0,
until === -1 ? 400 : until,
);
throw new Error(message);
}
throw error;
}
Current error:
json
{
"name": "BamlValidationError",
"message": "BamlValidationError: LLM Failure: Request failed with status code: 400 Bad Request, \n{\"error\":{\"message\":\"This model's maximum context length is 6114 tokens. However, your request has 10147 input tokens. Please reduce the length of the input messages. None\",\"type\":\"BadRequestError\",\"param\":null,\"code\":400}} (Unspecified error code: 400) - LLM client \"AiClient\" failed with status code: Unspecified error code: 400\nMessage: Request failed with status code: 400 Bad Request, \n<REPEATED JSON>",
"raw_output": "",
"prompt": "<PROMPT>",
"detailed_message": "..."
}Vaibhav (BAML π)
01/15/2026, 3:09 PMZouabi
01/16/2026, 5:04 AMBamlValidationError with another property llm_client_error for example, that has the response from the LLM Client.Vaibhav (BAML π)
01/16/2026, 5:06 AMVaibhav (BAML π)
01/16/2026, 5:07 AMZouabi
01/16/2026, 5:07 AMVaibhav (BAML π)
01/16/2026, 5:08 AMVaibhav (BAML π)
01/16/2026, 5:08 AMVaibhav (BAML π)
01/16/2026, 5:08 AMZouabi
01/16/2026, 5:09 AMZouabi
01/16/2026, 5:11 AMBamlError but in TypeScript all BAML errors extend Error instead.
> When BAML raises an exception, it will be an instance of a subclass of BamlError. This allows you to catch all BAML-specific exceptions with a single except block.Zouabi
01/16/2026, 5:13 AMBamlError as well instead of type
ts
export type BamlErrors = BamlClientHttpError | BamlValidationError | BamlClientFinishReasonError | BamlAbortError | BamlTimeoutError;
export declare function isBamlError(error: unknown): error is BamlErrors;
export declare function toBamlError(error: unknown): BamlErrors | Error;Vaibhav (BAML π)
01/16/2026, 5:13 AMVaibhav (BAML π)
01/16/2026, 5:13 AMVaibhav (BAML π)
01/16/2026, 5:13 AMVaibhav (BAML π)
01/16/2026, 5:14 AMVaibhav (BAML π)
01/16/2026, 5:14 AMZouabi
01/16/2026, 5:18 AMts
class BamlError extends Error
class BamlClientError extends BamlError
class BamlClientHttpError extends BamlClientError
class BamlValidationError extends BamlError
what do you think?Vaibhav (BAML π)
01/16/2026, 5:19 AMVaibhav (BAML π)
01/16/2026, 5:19 AMVaibhav (BAML π)
01/16/2026, 5:19 AMVaibhav (BAML π)
01/16/2026, 5:20 AMVaibhav (BAML π)
01/16/2026, 5:20 AMZouabi
01/16/2026, 5:22 AMBamlClientError)?
this is current errors.d.ts
ts
export declare class BamlClientFinishReasonError extends Error {
}
export declare class BamlValidationError extends Error {
}
export declare class BamlClientHttpError extends Error {
}
export declare class BamlAbortError extends Error {
}
export declare class BamlTimeoutError extends BamlClientHttpError {
}
export type BamlErrors = BamlClientHttpError | BamlValidationError | BamlClientFinishReasonError | BamlAbortError | BamlTimeoutError;
export declare function isBamlError(error: unknown): error is BamlErrors;
export declare function toBamlError(error: unknown): BamlErrors | Error;Zouabi
01/16/2026, 5:25 AMerror instanceof BamlClientHttpError nothing would break on their sideVaibhav (BAML π)
01/16/2026, 5:26 AMZouabi
01/16/2026, 5:27 AMBamlClientError if you'd want to match the rust sdk (this is what i think the tests assert but as part of the message instead of .toBeInstanceof)Zouabi
01/16/2026, 5:28 AMVaibhav (BAML π)
01/16/2026, 5:29 AMZouabi
01/16/2026, 5:36 AMdiff
+export declare class BamlError extends Error {
+}
+
-export declare class BamlClientFinishReasonError extends Error {
+export declare class BamlClientFinishReasonError extends BamlError {
}
-export declare class BamlValidationError extends Error {
+export declare class BamlValidationError extends BamlError {
}
+export declare class BamlClientError extends BamlError {
+}
-export declare class BamlClientHttpError extends Error {
+export declare class BamlClientHttpError extends BamlClientError {
}
-export declare class BamlAbortError extends Error {
+export declare class BamlAbortError extends BamlError { // or correct parent from CORE
}
export declare class BamlTimeoutError extends BamlClientHttpError {
}
-export type BamlErrors = BamlClientHttpError | BamlValidationError | BamlClientFinishReasonError | BamlAbortError | BamlTimeoutError;
-export declare function isBamlError(error: unknown): error is BamlErrors;
+export declare function isBamlError(error: unknown): error is BamlError;
// one issue here: this method accepts unknown but returns `Error` which is incorrect
// might be better to return "BamlError|null", had to look at source code to know it returns same error if it's NOT a valid BamlError
-export declare function toBamlError(error: unknown): BamlErrors | Error;
// either
+export declare function toBamlError<T>(error: T): BamlError | T;
// or
+export declare function toBamlError(error: unknown): BamlError | null;Vaibhav (BAML π)
01/16/2026, 5:37 AMVaibhav (BAML π)
01/16/2026, 5:37 AMZouabi
01/16/2026, 5:39 AMZouabi
01/16/2026, 5:41 AMVaibhav (BAML π)
01/16/2026, 6:10 AMVaibhav (BAML π)
01/16/2026, 6:11 AMVaibhav (BAML π)
01/16/2026, 6:12 AMsh
git clone
cd baml
# assuming you already have mise installed
mise install
pnpm i
cd integ-tests/typescript
pnpm build:dev
pnpm test <specifier to run the test you want>Vaibhav (BAML π)
01/16/2026, 6:12 AMVaibhav (BAML π)
01/16/2026, 6:12 AMVaibhav (BAML π)
01/16/2026, 6:13 AMZouabi
01/16/2026, 7:14 AMmise i
mise WARN Failed to resolve tool version list for npm:pnpm: [~/dev/BoundaryML/baml/mise.toml] npm:pnpm@10.14.0: timed out after 20.00s
mise WARN Failed to resolve tool version list for npm:pnpm: [~/dev/BoundaryML/baml/mise.toml] npm:pnpm@10.14.0: timed out after 20.00sZouabi
01/16/2026, 7:18 AMVaibhav (BAML π)
01/16/2026, 8:19 AMVaibhav (BAML π)
01/16/2026, 8:19 AMZouabi
01/16/2026, 10:47 AMmise use rust to fix first error "cargo: command not found"
then got the other error: error: component....Antonio Sarosi (BAML π)
01/17/2026, 12:55 AMAntonio Sarosi (BAML π)
01/17/2026, 12:56 AMAntonio Sarosi (BAML π)
01/17/2026, 12:56 AMAntonio Sarosi (BAML π)
01/17/2026, 1:02 AMZouabi
01/17/2026, 3:07 PM