JuliusBrussee/caveman · error

tool call requires function type, id, function name, and…

Error message

tool call requires function type, id, function name, and JSON arguments

What it means

Sentinel from validateCorpusMessage's tool-call loop: a ToolCall has type != "function", an empty/oversized ID (bound 2048), an empty/oversized function name (bound 512), or arguments that fail validUniqueJSONObject. All four parts of a well-formed function tool call are mandatory.

Solutions

  1. Set each tool call's type to "function"
  2. Provide a non-empty id within 2048 chars and a function name within 512 chars
  3. Make function.arguments a valid JSON object without duplicate keys (empty arguments can be "{}")
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at cacheengine/cachebench/corpus.go:375 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/7fe5b6ad8dc03c01. Report an issue: GitHub.

Appendix: source

Thrown at cacheengine/cachebench/corpus.go:375

	}
	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
}

func appendCorpusRow(rows *[]CorpusRow, sessions map[string]bool, retainedBytes *int64, row CorpusRow, limits CorpusLimits) error {
	if len(*rows) >= limits.MaxRows {
		return fmt.Errorf("row limit %d exceeded", limits.MaxRows)
	}
	if !sessions[row.SessionID] {
		if len(sessions) >= limits.MaxSessions {

View on GitHub (pinned to 766dce6b13)