JuliusBrussee/caveman · error
content must be string or null
Error message
content must be string or null
What it means
Sentinel from validateCorpusMessage: the decoded content value is non-nil but not a Go string. Content must be either JSON null (mapped to empty) or a JSON string; numbers, booleans, arrays, or objects as the top-level content are rejected.
Solutions
- Serialize message content as a plain JSON string, e.g. "content": "text..."
- Express structured content (arrays of parts) as its JSON-encoded string if the corpus format demands string content
- Use null content only on tool-call turns
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at cacheengine/cachebench/corpus.go:369 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/13ef6a8386a37817.
Report an issue: GitHub.
Appendix: source
Thrown at cacheengine/cachebench/corpus.go:369
}
if !validBoundedText(message.ToolCallID, 2048, true) || !validBoundedText(message.Name, 512, true) {
return errors.New("invalid message identity")
}
if len(message.Content) == 0 && len(message.ToolCalls) == 0 {
return errors.New("content or tool_calls required")
}
if len(message.Content) > limits.MaxMessageBytes || (len(message.Content) > 0 && !json.Valid(message.Content)) {
return errors.New("content invalid or exceeds limit")
}
messageBytes := len(message.Content) + len(message.Role) + len(message.ToolCallID) + len(message.Name)
if len(message.Content) > 0 {
var content any
if err := json.Unmarshal(message.Content, &content); err != nil {
return errors.New("content must decode")
}
if content != nil {
if _, ok := content.(string); !ok {
return errors.New("content must be string or null")
}
}
}
for _, call := range message.ToolCalls {
if call.Type != "function" || !validBoundedText(call.ID, 2048, false) || !validBoundedText(call.Function.Name, 512, false) || !validUniqueJSONObject([]byte(call.Function.Arguments)) {
return errors.New("tool call requires function type, id, function name, and JSON arguments")
}
messageBytes += len(call.ID) + len(call.Type) + len(call.Function.Name) + len(call.Function.Arguments)
}
if messageBytes > limits.MaxMessageBytes {
return errors.New("message exceeds byte limit")
}
if message.Role == "tool" && message.ToolCallID == "" {
return errors.New("tool message requires tool_call_id")
}
return nil
}
View on GitHub (pinned to 766dce6b13)