Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

[BUG] rag: detectFormat never recognizes top-level JSON arrays, so "auto" chunking skips the JSON chunker

Open Beginner friendly
#1,458 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@Theater-ahyeon is already working on this.

Since Oct 17, 2026.

  • #1459 by @Theater-ahyeon — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
typescript
Domain
backend

Research direction

Start with packages/rag/src/utils/format-detector.ts and inspect the bracket checks in detectFormat; the reproduction shows an array currently returns "text" while an object returns "json". Check for existing tests of format detection, then add coverage for a top-level array and confirm objects and malformed input still behave as expected. Done means valid top-level JSON arrays are detected as json, allowing auto chunking to select the JSON chunker.

Written by the indexing model from the issue text.

Description

Describe the bug

packages/rag/src/utils/format-detector.ts decides whether the input is JSON with:

if ((text.startsWith("{") || text.startsWith("[")) && text.endsWith("}")) {

The opening check accepts { or [, but the closing check only ever accepts }. A top-level JSON array ends with ], so it can never satisfy the condition and the JSON.parse branch is never reached for arrays.

Steps To Reproduce
import { detectFormat } from "../utils/format-detector"; // packages/rag/src/utils/format-detector.ts

detectFormat('[{"id":1},{"id":2}]'); // returns "text", expected "json"
detectFormat('{"id":1}');            // returns "json"

Reproduced on main at 72a46c7. No API key or network needed — detectFormat is a pure function.

Expected behavior

A well-formed top-level JSON array should be detected as json.

Impact

detectStrategy() in packages/rag/src/document/transformers.ts maps the detected format to a chunker, so with strategy: "auto" any document whose content is a JSON array — API response dumps, exported record sets, .json fixtures — is routed to RecursiveChunker instead of JsonChunker. The structural path: value representation and the fields / samplePaths metadata are silently not produced.

Objects ({ ... }) are unaffected, so this only misroutes array payloads.

Notes
  • Possible fix: pair the brackets, i.e. (text.startsWith("{") && text.endsWith("}")) || (text.startsWith("[") && text.endsWith("]")). The existing JSON.parse in a try/catch still guards against malformed input.
  • While testing this I hit a separate, unrelated problem: JsonChunker spreads the token chunker's metadata into buildMetadata's extra, and buildMetadata does Object.assign(meta, params.extra), so the format: "json" it sets is overwritten by the inherited format: "text". sourceType is explicitly stripped from the inherited metadata but format is not. I am not bundling that with a fix for this issue — happy to open a separate one if useful.
Dominant language
TypeScript
Stars
10.9k
Forks
1.3k
Avg merge
4h 57m
Merged PRs (30d)
2

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from VoltAgent/voltagent

All issues in VoltAgent/voltagent

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.