BoundaryML/baml · error

`--sdk-import-path` is only valid for the Go generator

Error message

`--sdk-import-path` is only valid for the Go generator

What it means

Argument-compatibility guard in `baml generate`: the --sdk-import-path flag was supplied with a non-Go output type. The flag only configures the import path prefix emitted by the Go code generator; for every other generator it is meaningless, and accepting it would embed a Go-specific setting into a generated manifest that other generators' readers reject anyway.

Source

Thrown at baml_language/crates/baml_cli/src/generate.rs:137

        // 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()),
        );
        Ok(crate::ExitCode::Success)
    }
}

fn parse_add_output_type(value: &str) -> Result<OutputType, String> {

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Remove --sdk-import-path when the output type is not Go.
  2. Switch --output-type to go if you actually intend to generate a Go SDK.
  3. In scripts, add the flag conditionally only when output type is go.

Example fix

// before
baml generate add-generator --output-type python --sdk-import-path github.com/x/y/baml_sdk
// after
baml generate add-generator --output-type python
Defensive patterns

Strategy: validation

Validate before calling

const args = ['add-generator', '--output-type', outputType];
if (outputType === 'go') args.push('--sdk-import-path', goModule + '/baml_sdk');

Prevention

When it happens

Trigger: `baml generate add-generator --output-type python --sdk-import-path ...` (or typescript, or no output type) — any non-Go output type combined with `--sdk-import-path`.

Common situations: Copy-pasting a Go command template while editing the output type; scripting that always appends --sdk-import-path regardless of target language.

Related errors


AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12). Data as JSON: /api/errors/551145fbd6528dcd. Report an issue: GitHub.