BoundaryML/baml · error
Could not determine mime type for PDF input. Only applicatio
Error message
Could not determine mime type for PDF input. Only application/pdf is allowed.
What it means
BAML only accepts PDFs whose MIME type is application/pdf for PDF media inputs. When a base64 data URL or file is supplied for a pdf input but the MIME type cannot be inferred at all, process_media bails with this error rather than sending an untyped payload to the LLM provider.
Source
Thrown at engine/baml-runtime/src/internal/llm_client/traits/mod.rs:624
}
if mime_type.is_none() {
if let Some(t) = infer::get(&bytes) {
mime_type = Some(t.mime_type().to_string());
}
}
// ENFORCEMENT: For PDF, the mime type must be application/pdf
if part.media_type == BamlMediaType::Pdf {
match &mime_type {
Some(mt) if mt != "application/pdf" => {
anyhow::bail!(
"File provided for PDF input is not a PDF. Detected mime type: '{}'. Only application/pdf is allowed.",
mt
);
}
None => {
anyhow::bail!(
"Could not determine mime type for PDF input. Only application/pdf is allowed."
);
}
_ => {}
}
}
Ok(BamlMedia::base64(
part.media_type,
if render_settings.as_shell_commands {
format!(
"$(base64 '{}')",
media_path
.strip_prefix("file://")
.unwrap_or(media_path.as_str())
)
} else {
BASE64_STANDARD.encode(&bytes)View on GitHub (pinned to bd85ce9dee)
Solutions
- Prefix the media value with a data URL: data:application/pdf;base64,<payload>
- Verify the file is actually a valid PDF (starts with %PDF-) and not corrupted
- If using a URL instead of base64, ensure the server serves Content-Type application/pdf so inference succeeds
- Check you declared the parameter type as pdf in the BAML schema and are not reusing an image value
Example fix
// before client.messages(media_content=b64_pdf_string) // after client.messages(media_content="data:application/pdf;base64," + b64_pdf_string)
Defensive patterns
Strategy: validation
Validate before calling
function isPdfInput(media) {
const isPdfDataUrl = /^data:application\/pdf;base64,/.test(media);
const decoded = Buffer.from(media.replace(/^data:\w+\/\w+;base64,/, ''), 'base64');
const hasPdfMagic = decoded.subarray(0, 5).toString() === '%PDF-';
return isPdfDataUrl || hasPdfMagic;
}
if (!isPdfInput(mediaValue)) throw new Error('Input must be a valid application/pdf data URL or PDF bytes'); Type guard
const isPdfDataUrl = (s) => typeof s === 'string' && /^data:application\/pdf;base64,[A-Za-z0-9+/=]+$/.test(s);
Prevention
- Always wrap raw base64 PDFs in a data:application/pdf;base64, prefix
- Validate the %PDF- magic bytes before sending
- Don't reuse image-typed media variables for PDF parameters
When it happens
Trigger: A media value for a pdf-typed BAML parameter lacks a data: URL prefix with a mime type and no decodable magic bytes, so infer returns None (as_base64 yields no mime type).
Common situations: Passing a raw base64 string without a data:application/pdf;base64, prefix; uploading a scanned/corrupted PDF whose magic bytes were stripped; renaming a non-PDF file to .pdf and sending its base64.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- File provided for PDF input is not a PDF. Detected mime type
- Requested media of MIME type '{}' but fetched '{}' from URL
- baml.media.image.from_url expects 1 argument, got {} at {:?}
- baml.media.image.from_url expects a string argument at {:?}
- Could not unify Media with {:?}
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/fb36789093c1cc7a.
Report an issue: GitHub.