JuliusBrussee/caveman · error

corpus provider conversion supports string or null content

Error message

corpus provider conversion supports string or null content

What it means

Sentinel from contentText during corpus-to-provider body conversion: the message's raw content bytes are non-null and do not unmarshal into a plain string. The provider converters accept only string or null content (the shapes validateCorpusMessage enforces), so non-string content here means the row bypassed or drifted from that validation.

Solutions

  1. Normalize corpus content to a JSON string or null during corpus import
  2. Ensure rows always pass validateCorpusWire/validateCorpusMessage before conversion
  3. Serialize structured content blocks into their JSON string form for the corpus format
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at cacheengine/cachebench/corpus.go:734 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of JuliusBrussee/caveman@766dce6b13 (2026-08-18). Data as JSON: /api/errors/6470de1a57733230. Report an issue: GitHub.

Appendix: source

Thrown at cacheengine/cachebench/corpus.go:734

		return anthropicCorpusBody(provider.Model, messages)
	case "bedrock":
		return bedrockCorpusBody(messages)
	case "gemini":
		return geminiCorpusBody(messages)
	default:
		return nil, fmt.Errorf("unsupported corpus provider %q", provider.Provider)
	}
}

func contentText(content json.RawMessage) (string, error) {
	if len(content) == 0 || bytes.Equal(bytes.TrimSpace(content), []byte("null")) {
		return "", nil
	}
	var text string
	if err := json.Unmarshal(content, &text); err == nil {
		return text, nil
	}
	return "", errors.New("corpus provider conversion supports string or null content")
}

func anthropicCorpusBody(model string, messages []CorpusMessage) ([]byte, error) {
	var system []string
	converted := make([]any, 0, len(messages))
	for _, message := range messages {
		text, err := contentText(message.Content)
		if err != nil {
			return nil, err
		}
		switch message.Role {
		case "system", "developer":
			if text != "" {
				system = append(system, text)
			}
		case "assistant":
			blocks := make([]any, 0, len(message.ToolCalls)+1)
			if text != "" {

View on GitHub (pinned to 766dce6b13)