{"record":{"id":"a59cd747ddc2de98","repo":"docling-project/docling","slug":"label-must-be-either-code-or-formula-a59cd7","errorCode":null,"errorMessage":"Label must be either code or formula","messagePattern":"Label must be either code or formula","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"docling/models/stages/code_formula/code_formula_vlm_model.py","lineNumber":152,"sourceCode":"\n    def _get_prompt(self, label: str) -> str:\n        \"\"\"Construct the prompt for the model based on the element type.\n\n        Args:\n            label: The type of input, either 'code' or 'formula'\n\n        Returns:\n            The prompt string\n\n        Raises:\n            NotImplementedError: If the label is not 'code' or 'formula'\n        \"\"\"\n        if label == \"code\":\n            return \"<code>\"\n        elif label == \"formula\":\n            return \"<formula>\"\n        else:\n            raise NotImplementedError(\"Label must be either code or formula\")\n\n    def _extract_code_language(self, input_string: str) -> Tuple[str, Optional[str]]:\n        \"\"\"Extract programming language from the beginning of a string.\n\n        Checks if the input string starts with a pattern of the form\n        ``<_some_language_>``. If it does, extracts the language string.\n\n        Args:\n            input_string: The input string, which may start with ``<_language_>``\n\n        Returns:\n            Tuple of (remainder, language) where:\n            - remainder is the string after the language tag (or original if no match)\n            - language is the extracted language if found, otherwise None\n        \"\"\"\n        pattern = r\"^<_([^_>]+)_>\\s*(.*)\"\n        match = re.match(pattern, input_string, flags=re.DOTALL)\n        if match:","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/docling-project/docling/blob/61d76f1ff3f8428065465889f7b4577da7df704c/docling/models/stages/code_formula/code_formula_vlm_model.py#L134-L170","documentation":"The VLM-based code/formula model builds its prompt token from an element label; only 'code' and 'formula' are accepted, returning '<code>' or '<formula>'. Any other label raises NotImplementedError, signalling the caller routed an unsupported element type into this stage. It is a strict contract on the input labels, not a runtime/model failure.","triggerScenarios":"Passing elements to GraniteVlmCodeFormulaModel whose label is anything other than the exact strings 'code' or 'formula' — for example 'title', 'list_item', or a mistyped/uppercased label like 'Code'.","commonSituations":"Custom pipelines that skip the label filter; label enum mismatches after a docling upgrade; reusing items from another backend whose labels were never normalized to docling's enum values.","solutions":["Filter element batches to labels 'code' and 'formula' before invoking the model (mirror what the standard pipeline stage does).","Normalize labels: assert/convert item.label to the expected lowercase enum value before building the prompt.","Add a unit check in your pipeline that the set of labels reaching this model is a subset of {'code','formula'}."],"exampleFix":"# before\nquery = self._get_query(item.label)  # raises NotImplementedError for 'picture'\n\n# after\nif item.label in (\"code\", \"formula\"):\n    query = self._get_query(item.label)\nelse:\n    _log.debug(f\"Skipping item with unsupported label {item.label!r}\")\n    return","handlingStrategy":"validation","validationCode":"SUPPORTED = {\"code\", \"formula\"}\nitems = [i for i in items if i.label in SUPPORTED]","typeGuard":"def is_code_or_formula(label: str) -> bool:\n    return label in (\"code\", \"formula\")","tryCatchPattern":null,"preventionTips":["Apply the same label filter as error 261 — never route arbitrary labels into the VLM stage.","Normalize custom labels to docling enum values at ingestion time.","Add pipeline assertions that label sets are subsets of {'code','formula'} before dispatch."],"tags":["code-formula","vlm","label","not-implemented"],"backgroundTag":null,"analyzedSha":"61d76f1ff3f8428065465889f7b4577da7df704c","analyzedAt":"2026-08-14T23:53:18.727Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}