alibaba/open-code-review · error

background file %q must not contain the reserved delimiters

Error message

background file %q must not contain the reserved delimiters %q or %q

What it means

The background content is wrapped in the reserved delimiters <ocr_user_background> and </ocr_user_background> before being placed in the review prompt. If the user's own file already contains either tag, the wrapping would produce nested or spoofed delimiters that break prompt parsing. loadBackgroundFile rejects such files outright.

Source

Thrown at cmd/opencodereview/background_file.go:92

	if info.Size() > maxBackgroundFileBytes {
		return "", fmt.Errorf(
			"background file %q is %d bytes, exceeding the maximum of %d bytes; please provide a smaller file",
			path, info.Size(), maxBackgroundFileBytes,
		)
	}

	raw, err := os.ReadFile(path)
	if err != nil {
		return "", fmt.Errorf("read background file %q: %w", path, err)
	}

	cleaned := sanitizeMarkdown(string(raw))
	if cleaned == "" {
		return "", fmt.Errorf("background file %q is empty after sanitisation", path)
	}

	if strings.Contains(cleaned, backgroundOpenTag) || strings.Contains(cleaned, backgroundCloseTag) {
		return "", fmt.Errorf(
			"background file %q must not contain the reserved delimiters %q or %q",
			path, backgroundOpenTag, backgroundCloseTag,
		)
	}

	// Enforce the limits on the cleaned content only: the wrapper delimiters add
	// overhead the user cannot control, so counting them would make the reported
	// character count misleading.
	if n := len([]rune(cleaned)); n > backgroundHardLimit {
		return "", fmt.Errorf(
			"background content is %d characters, exceeding the hard limit of %d (aborting)",
			n, backgroundHardLimit,
		)
	} else if n > backgroundSoftLimit {
		fmt.Fprintf(os.Stderr,
			"[ocr] --background-file content is %d characters, exceeding the recommended %d (continuing but review quality might be impacted)\n",
			n, backgroundSoftLimit,
		)

View on GitHub (pinned to 5cf97d0d15)

Solutions

  1. Edit the file and remove or reword the literal `<ocr_user_background>` / `</ocr_user_background>` strings.
  2. Escape by rephrasing, e.g. write 'the ocr user background tag' instead of the literal tag.
  3. Move conflicting example content into a different document that is not passed as --background-file.
  4. Pass the content inline with --background only after stripping the tags.

Example fix

// before (background.md)
Example: <ocr_user_background>your notes here</ocr_user_background>
// after (background.md)
Example: ocr-user-background tags wrap your notes; do not type them literally.
Defensive patterns

Strategy: validation

Validate before calling

// Go: reject files containing the reserved delimiters before invoking ocr
if strings.Contains(content, "<ocr_user_background>") || strings.Contains(content, "</ocr_user_background>") {
	return fmt.Errorf("%s contains reserved ocr delimiters", path)
}

Type guard

func containsReservedDelimiter(s string) bool {
	return strings.Contains(s, "<ocr_user_background>") || strings.Contains(s, "</ocr_user_background>")
}

Try / catch

if err := runOcrReview(backgroundFile); err != nil {
	if strings.Contains(err.Error(), "must not contain the reserved delimiters") {
		// sanitize the file programmatically and retry once
	}
}

Prevention

When it happens

Trigger: `ocr review --background-file <path>` where the file text contains the literal string `<ocr_user_background>` or `</ocr_user_background>` anywhere after sanitisation.

Common situations: Reusing an OCR-generated prompt artifact as background input; documenting ocr's prompt format inside a background file; copy-pasting examples from OCR docs into the background file.

Related errors


AI-assisted analysis of alibaba/open-code-review@5cf97d0d15 (2026-09-02). Data as JSON: /api/errors/ca16a9763f676822. Report an issue: GitHub.