BoundaryML/baml · error · Error
Pdf is not a URL
Error message
Pdf is not a URL
What it means
TypeScript client state guard: asUrl() was called on a BamlPdf whose internal type is 'base64', not 'url'. BamlPdf is a tagged union of the two representations; the accessor for the wrong tag throws rather than return base64 payload bytes where a URL is expected.
Source
Thrown at engine/language_client_typescript/typescript_src/pdf.ts:69
const response = await fetch(url);
const blob = await response.blob();
return BamlPdf.fromBlob(blob);
}
/**
* Check if the pdf is stored as a URL
*/
isUrl(): boolean {
return this.type === "url";
}
/**
* Get the URL of the pdf if it's stored as a URL
* @throws Error if the pdf is not stored as a URL
*/
asUrl(): string {
if (!this.isUrl()) {
throw new Error("Pdf is not a URL");
}
return this.content;
}
/**
* Get the base64 data and media type if the pdf is stored as base64
* @returns [base64Data, mediaType]
* @throws Error if the pdf is not stored as base64
*/
asBase64(): [string, string] {
if (this.type !== "base64") {
throw new Error("Pdf is not base64");
}
return [this.content, this.mediaType || ""];
}
/**
* Convert the pdf to a JSON representationView on GitHub (pinned to bd85ce9dee)
Solutions
- Guard with pdf.isUrl() before calling asUrl()
- Construct the Pdf from a URL (Pdf.fromUrl(...)) when URL access is required
- Branch on storage type and handle the base64 case with asBase64()
Example fix
// before
const url = pdf.asUrl(); // throws for base64 pdf
// after
if (pdf.isUrl()) {
const url = pdf.asUrl();
} else {
const [b64, mediaType] = pdf.asBase64();
} Defensive patterns
Strategy: type-guard
Validate before calling
if (!pdf.isUrl()) { /* handle base64 branch */ } Type guard
const isUrlPdf = (p) => p.isUrl();
Try / catch
try { const url = pdf.asUrl(); }
catch { const [b64, mt] = pdf.asBase64(); } Prevention
- Check isUrl() before asUrl()
- Branch on storage type in shared document-handling code
- Prefer URL construction when downstream code needs links
When it happens
Trigger: Calling pdf.asUrl() on a Pdf constructed from base64 (fromBase64) or another non-URL source, where isUrl() is false.
Common situations: Displaying or sharing PDF links while the document was inlined as base64 (common when passing file bytes to LLMs); mixing URL-loaded and byte-loaded documents in the same code path.
Understand the failure class
Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.
Related errors
- BAML internal error (AWSBedrock): Pdf file should have been
- Audio is not a URL
- Image is not a URL
- Pdf is not base64
- BAML internal error (AWSBedrock): file should have been reso
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/1a8c7fece6c640a8.
Report an issue: GitHub.