{"record":{"id":"5332dd01e980dc69","repo":"deepset-ai/haystack","slug":"header-split-levels-contains-invalid-values-inva","errorCode":null,"errorMessage":"header_split_levels contains invalid values: {invalid}. All levels must be integers between 1 and 6.","messagePattern":"header_split_levels contains invalid values: (.+?)\\. All levels must be integers between 1 and 6\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"haystack/components/preprocessors/markdown_header_splitter.py","lineNumber":65,"sourceCode":"            all levels `[1, 2, 3, 4, 5, 6]`.\n        :param secondary_split: Optional secondary split condition after header splitting.\n            Options are None, \"word\", \"passage\", \"period\", \"line\". Defaults to None.\n        :param split_length: The maximum number of units in each split when using secondary splitting. Defaults to 200.\n        :param split_overlap: The number of overlapping units for each split when using secondary splitting.\n            Defaults to 0.\n        :param split_threshold: The minimum number of units per split when using secondary splitting. Defaults to 0.\n        :param skip_empty_documents: Choose whether to skip documents with empty content. Default is True.\n            Set to False when downstream components in the Pipeline (like LLMDocumentContentExtractor) can extract text\n            from non-textual documents.\n        \"\"\"\n        if header_split_levels is None:\n            header_split_levels = [1, 2, 3, 4, 5, 6]\n\n        if not isinstance(header_split_levels, list) or len(header_split_levels) == 0:\n            raise ValueError(\"header_split_levels must be a non-empty list.\")\n        invalid = [lvl for lvl in header_split_levels if not isinstance(lvl, int) or lvl < 1 or lvl > 6]\n        if invalid:\n            raise ValueError(\n                f\"header_split_levels contains invalid values: {invalid}. All levels must be integers between 1 and 6.\"\n            )\n        if len(header_split_levels) != len(set(header_split_levels)):\n            raise ValueError(\"header_split_levels must not contain duplicate values.\")\n\n        self.page_break_character = page_break_character\n        self.secondary_split = secondary_split\n        self.split_length = split_length\n        self.split_overlap = split_overlap\n        self.split_threshold = split_threshold\n        self.skip_empty_documents = skip_empty_documents\n        self.keep_headers = keep_headers\n        self.header_split_levels = header_split_levels\n        self._header_split_levels_set = set(header_split_levels)\n        self._header_pattern = re.compile(r\"(?m)^(#{1,6}) (.+)$\")  # ATX-style .md-headers\n\n        # Matches fenced code blocks delimited by triple backticks (```) or triple tildes (~~~).\n        # Broken down:","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/deepset-ai/haystack/blob/e318778c9bf60a1963e3b5f451359655dd696c30/haystack/components/preprocessors/markdown_header_splitter.py#L47-L83","documentation":"MarkdownHeaderSplitter's __init__ checks that every entry in header_split_levels is an int in the range 1..6 (markdown heading levels). If any element fails this check, ValueError is raised listing the invalid values.","triggerScenarios":"Passing header_split_levels=[0], [7], [\"1\"], [1.5], [None], or any list containing non-int or out-of-range values to MarkdownHeaderSplitter.","commonSituations":"Off-by-one thinking (markdown levels are 1-based, not 0-based), reading levels from user input/config as strings, or confusing heading level with heading count.","solutions":["Use only integers 1-6, e.g. header_split_levels=[1, 2, 3].","Convert string values from config: [int(lvl) for lvl in raw_levels].","Filter/validate levels before construction: levels = [l for l in levels if isinstance(l, int) and 1 <= l <= 6].","Check for bool values too, since bool is a subclass of int (True==1 passes the current check); normalize with int() deliberately."],"exampleFix":"// before\nMarkdownHeaderSplitter(header_split_levels=[0, 7])\nMarkdownHeaderSplitter(header_split_levels=[\"1\", \"2\"])\n// after\nMarkdownHeaderSplitter(header_split_levels=[1, 2])","handlingStrategy":"validation","validationCode":"levels = [int(l) for l in raw_levels if str(l).strip().isdigit()]\nlevels = [l for l in levels if 1 <= l <= 6]\nif not levels:\n    levels = [1, 2, 3]","typeGuard":"def all_levels_valid(levels) -> bool:\n    return all(isinstance(l, int) and not isinstance(l, bool) and 1 <= l <= 6 for l in levels)","tryCatchPattern":"try:\n    splitter = MarkdownHeaderSplitter(header_split_levels=levels)\nexcept ValueError as e:\n    raise ConfigError(f\"header_split_levels invalid: {e}\") from e","preventionTips":["Markdown heading levels are 1-6 (h1-h6); never use 0 or 7.","Cast string config values with int() before passing.","Filter out-of-range levels instead of passing them through."],"tags":["python","validation","range-check","haystack"],"backgroundTag":"invalid-constructor-argument","analyzedSha":"e318778c9bf60a1963e3b5f451359655dd696c30","analyzedAt":"2026-08-30T11:45:20.711Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}