Tencent/WeKnora · error

%s exceeds %d characters

Error message

%s exceeds %d characters

What it means

validatePromptInstructionFields enforces MaxCustomPromptInstructionsLength on every knowledge-base / effective-process prompt instruction field. If any field's rune length exceeds the limit, it fails with "<fieldName> exceeds <limit> characters".

Source

Thrown at internal/types/prompt_instructions.go:85

	return validatePromptInstructionFields(fields)
}

// ValidateEffectiveProcessPromptInstructions checks length limits on the
// merged per-upload effective config.
func ValidateEffectiveProcessPromptInstructions(eff EffectiveProcessConfig) error {
	fields := map[string]string{
		"table metadata instructions":      eff.ChunkingConfig.TableMetadataInstructions,
		"image instructions":               eff.VLMConfig.CustomInstructions,
		"question generation instructions": eff.QuestionGenerationConfig.CustomInstructions,
		"graph extraction instructions":    eff.ExtractConfig.CustomInstructions,
	}
	return validatePromptInstructionFields(fields)
}

func validatePromptInstructionFields(fields map[string]string) error {
	for name, value := range fields {
		if len([]rune(value)) > MaxCustomPromptInstructionsLength {
			return fmt.Errorf("%s exceeds %d characters", name, MaxCustomPromptInstructionsLength)
		}
	}
	return nil
}

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Trim the offending field to MaxCustomPromptInstructionsLength runes before validation
  2. Show the character count in the UI and block submission over the limit
  3. Split long instructions across multiple fields or use summarization
  4. Check the constant's current value — if the limit legitimately changed, update stored content or migrate

Example fix

// before
instructions["system"] = veryLongText // > limit
// after
runes := []rune(veryLongText)
if len(runes) > MaxCustomPromptInstructionsLength {
    instructions["system"] = string(runes[:MaxCustomPromptInstructionsLength])
}
Defensive patterns

Strategy: validation

Validate before calling

func withinLimit(fields map[string]string) bool {
    for _, v := range fields {
        if len([]rune(v)) > MaxCustomPromptInstructionsLength { return false }
    }
    return true
}

Type guard

func fieldWithinLimit(s string) bool { return len([]rune(s)) <= MaxCustomPromptInstructionsLength }

Try / catch

if err := validatePromptInstructionFields(fields); err != nil {
    // err text names the offending field, e.g. "system exceeds 2000 characters"
    fieldName := strings.SplitN(err.Error(), " ", 2)[0]
    // highlight fieldName in the UI
}

Prevention

When it happens

Trigger: Calling ValidateKnowledgeBasePromptInstructions or ValidateEffectiveProcessPromptInstructions with a map of prompt instruction fields where any value exceeds MaxCustomPromptInstructionsLength runes.

Common situations: Users pasting very long custom instructions into a knowledge-base or process editor, programmatic imports of large prompt templates, or accumulated instruction text growing past the cap across edits.

Related errors


AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02). Data as JSON: /api/errors/659d1799e1ca7d09. Report an issue: GitHub.