BoundaryML/baml · error

unexpected type for SSE chunks: %T

Error message

unexpected type for SSE chunks: %T

What it means

SSEChunks() expects the runtime to return []raw_objects.RawPointer, each castable to SSEResponse. If the top-level result is not a RawPointer slice (e.g. nil or another container), it fails with "unexpected type for SSE chunks: %T". Note the per-element chunk.(SSEResponse) later in the function can also panic on element type mismatch.

Source

Thrown at engine/language_client_go/pkg/rawobjects_llm_stream_call.go:31

}

func newLLMStreamCall(ptr int64, rt unsafe.Pointer) LLMStreamCall {
	return &llmStreamCall{&llmCall{raw_objects.FromPointer(ptr, rt)}}
}

func (l *llmStreamCall) ObjectType() cffi.BamlObjectType {
	return cffi.BamlObjectType_OBJECT_LLM_STREAM_CALL
}

func (l *llmStreamCall) SSEChunks() ([]SSEResponse, error) {
	result, err := raw_objects.CallMethod(l, "sse_chunks", nil)
	if err != nil {
		return nil, fmt.Errorf("failed to get SSE chunks: %w", err)
	}

	casted, ok := result.([]raw_objects.RawPointer)
	if !ok {
		return nil, fmt.Errorf("unexpected type for SSE chunks: %T", result)
	}

	chunks := make([]SSEResponse, len(casted))
	for i, chunk := range casted {
		chunks[i] = chunk.(SSEResponse)
	}

	return chunks, nil
}

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Only call SSEChunks() after a successful, completed stream
  2. Treat "unexpected type" as empty-chunk-set and fall back to stream error info
  3. Update generated client and runtime together

Example fix

// before
chunks, err := streamCall.SSEChunks()
// after
chunks, err := streamCall.SSEChunks()
if err != nil {
    if strings.Contains(err.Error(), "unexpected type") {
        chunks = nil // stream produced no SSE chunks
    } else {
        return err
    }
}
Defensive patterns

Strategy: type-guard

Type guard

// Go
chunks, err := streamCall.SSEChunks()
if err != nil {
    if strings.Contains(err.Error(), "unexpected type") {
        chunks = nil // treat as empty chunk set
    } else {
        return err
    }
}

Try / catch

// Go: fall back to empty chunks on shape mismatch
if err != nil && strings.Contains(err.Error(), "unexpected type for SSE chunks") {
    chunks = nil
}

Prevention

When it happens

Trigger: Calling SSEChunks() when the runtime returns nil (no chunks recorded, e.g. stream never started or failed early) or a differently shaped collection due to version skew.

Common situations: Inspecting a stream call that errored before producing any SSE events; generated client built against an older runtime with a different chunk serialization.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


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