siyuan-note/siyuan · error

SVG images are not accepted by multimodal models

Error message

SVG images are not accepted by multimodal models

What it means

Multimodal vision models accept raster images only. PrepareModelImage detects SVG by mime OR by a literal '<svg' in the first 512 bytes (catching mis-detected or mislabeled SVGs) and rejects before decode.

Source

Thrown at kernel/util/openai.go:630

			return
		}
		seen[index] = true
	}
	matched = true
	return
}

// PrepareModelImage 校验并按需缩放图片,尽量保留多模态模型支持的原始格式和图片质量。
func PrepareModelImage(data []byte, maxBytes, maxPixels, maxEdge int) (PreparedImage, error) {
	if len(data) == 0 {
		return PreparedImage{}, errors.New("image data is empty")
	}
	if maxBytes > 0 && len(data) > maxBytes {
		return PreparedImage{}, fmt.Errorf("image exceeds size limit: %d bytes", maxBytes)
	}
	mimeType := mimetype.Detect(data).String()
	if strings.Contains(mimeType, "svg") || bytes.Contains(bytes.ToLower(data[:min(len(data), 512)]), []byte("<svg")) {
		return PreparedImage{}, errors.New("SVG images are not accepted by multimodal models")
	}
	switch mimeType {
	case "image/gif", "image/jpeg", "image/png", "image/webp":
	default:
		return PreparedImage{}, fmt.Errorf("unsupported image type: %s", mimeType)
	}
	config, _, err := image.DecodeConfig(bytes.NewReader(data))
	if err != nil {
		return PreparedImage{}, errors.New("unsupported or invalid image: " + err.Error())
	}
	if config.Width < 1 || config.Height < 1 || maxPixels > 0 && int64(config.Width)*int64(config.Height) > int64(maxPixels) {
		return PreparedImage{}, fmt.Errorf("image exceeds pixel limit: %d", maxPixels)
	}

	decoded, err := imaging.Decode(bytes.NewReader(data), imaging.AutoOrientation(true))
	if err != nil {
		return PreparedImage{}, errors.New("decode image failed: " + err.Error())
	}

View on GitHub (pinned to 251596fc0d)

Solutions

  1. Rasterize the SVG to PNG/JPEG before sending.
  2. Do not attach SVGs to vision prompts.
  3. Validate the true mime type before attaching.

Example fix

# rasterize the SVG to PNG before attaching, or exclude it from the vision context
Defensive patterns

Strategy: validation

Validate before calling

mt := mimetype.Detect(data).String()
if strings.Contains(mt, "svg") ||
    bytes.Contains(bytes.ToLower(data[:min(len(data),512)]), []byte("<svg")) {
    return errors.New("rasterize SVG before sending to a vision model")
}

Type guard

func IsSVG(data []byte) bool {
    return strings.Contains(mimetype.Detect(data).String(), "svg") ||
        bytes.Contains(bytes.ToLower(data[:min(len(data),512)]), []byte("<svg"))
}

Prevention

When it happens

Trigger: Attaching an SVG asset to a vision query; attaching a raster file whose extension says PNG/JPEG but whose content is SVG.

Common situations: SVG icons/illustrations dragged into a vision chat; asset renamed to .png but still SVG payload.

Related errors


AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12). Data as JSON: /api/errors/90e471907c5e6fc8. Report an issue: GitHub.