BoundaryML/baml · error
invalid Go SDK import path `{import_path}`
Error message
invalid Go SDK import path `{import_path}` What it means
When adding a Go generator with `--sdk-import-path`, the CLI validates the import path with `is_valid_go_import_path`. If the value fails validation (wrong shape, invalid characters, not of the expected `<MODULE>/baml_sdk` form), this error is thrown with the offending value interpolated.
Source
Thrown at baml_language/crates/baml_cli/src/generate.rs:131
let content = std::fs::read_to_string(&toml_path)
.with_context(|| format!("failed to read {}", toml_path.display()))?;
let manifest = baml_db::manifest::parse(&content)
.with_context(|| format!("failed to parse {}", toml_path.display()))?;
baml_db::manifest::package_name(&manifest, &toml_path)?;
// Every other manifest reader rejects these, so accepting them here
// would write a generator into a file that the next build refuses to
// load, reporting a failure that names neither this command nor the
// table it choked on.
baml_db::manifest::reject_stdlib_only_tables(&manifest, &toml_path)?;
let mut generator = Generator::from(self.output_type);
match (self.output_type, self.sdk_import_path.as_deref()) {
(OutputType::Go, Some(import_path)) if is_valid_go_import_path(import_path) => {
generator.sdk_import_path = Some(import_path.to_string());
}
(OutputType::Go, Some(import_path)) => {
anyhow::bail!("invalid Go SDK import path `{import_path}`");
}
(OutputType::Go, None) => {
anyhow::bail!("the Go generator requires `--sdk-import-path <MODULE>/baml_sdk`");
}
(_, Some(_)) => {
anyhow::bail!("`--sdk-import-path` is only valid for the Go generator");
}
(_, None) => {}
}
let (updated, name) = add_generator_to_manifest(&content, &generator)
.with_context(|| format!("failed to update {}", toml_path.display()))?;
std::fs::write(&toml_path, updated)
.with_context(|| format!("failed to write {}", toml_path.display()))?;
Reporter::new().finish(
"Added",
format!("generator.{name} to {}", toml_path.display()),View on GitHub (pinned to bd85ce9dee)
Solutions
- Provide a full Go module path ending in /baml_sdk: --sdk-import-path github.com/me/myapp/baml_sdk.
- Use forward slashes and valid Go module path characters (lowercase, no spaces).
- Check the generated module's go.mod module name and append /baml_sdk to it.
- If you don't have an import path yet, omit the flag and read the sibling error about the required format.
Example fix
// before --sdk-import-path ./local/sdk // after --sdk-import-path github.com/acme/myapp/baml_sdk
Defensive patterns
Strategy: validation
Validate before calling
const IMPORT_RE = /^[a-zA-Z0-9_.-]+(\/[a-zA-Z0-9_.-]+)*\/baml_sdk$/;
if (!IMPORT_RE.test(importPath)) throw new Error(`invalid Go SDK import path \`${importPath}\``); Type guard
function isValidGoImportPath(p: string): boolean {
return /^[\w.-]+(\/[\w.-]+)+\/baml_sdk$/.test(p);
} Prevention
- Copy the module name verbatim from go.mod and append /baml_sdk.
- Never pass filesystem paths; import paths use forward slashes.
- Lint scripts that construct --sdk-import-path values.
When it happens
Trigger: `baml generate add-generator` with output type Go and `--sdk-import-path` set to a string that fails `is_valid_go_import_path` — e.g. relative paths, paths with spaces/invalid Go module characters, or missing the `/baml_sdk` suffix.
Common situations: Typos in the module path, passing a local filesystem path instead of a Go import path, forgetting the /baml_sdk suffix, or using Windows-style backslashes.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- unknown feedback field(s) {}; only "title" and "description"
- feedback field "{key}" must be a string
- feedback needs a title; pass --title "..." or a JSON payload
- feedback payload must be a JSON object like {"title": "..."}
- the Go generator requires `--sdk-import-path <MODULE>/baml_s
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/ffeee1153d0772d8.
Report an issue: GitHub.