{"record":{"id":"f29ec54e2fd2e9b5","repo":"lancedb/lancedb","slug":"variable-names-cannot-contain-colons-f29ec5","errorCode":null,"errorMessage":"Variable names cannot contain colons","messagePattern":"Variable names cannot contain colons","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/python/lancedb/embeddings/registry.py","lineNumber":173,"sourceCode":"        # Note that metadata dictionary values must be bytes\n        # so we need to json dump then utf8 encode\n        metadata = json.dumps(json_data, indent=2).encode(\"utf-8\")\n        return {\"embedding_functions\": metadata}\n\n    def set_var(self, name: str, value: str) -> None:\n        \"\"\"\n        Set a variable. These can be accessed in embedding configuration using\n        the syntax `$var:variable_name`. If they are not set, an error will be\n        thrown letting you know which variable is missing. If you want to supply\n        a default value, you can add an additional part in the configuration\n        like so: `$var:variable_name:default_value`. Default values can be\n        used for runtime configurations that are not sensitive, such as\n        whether to use a GPU for inference.\n\n        The name must not contain a colon. Default values can contain colons.\n        \"\"\"\n        if \":\" in name:\n            raise ValueError(\"Variable names cannot contain colons\")\n        self._variables[name] = value\n\n    def get_var(self, name: str) -> str:\n        \"\"\"\n        Get a variable.\n        \"\"\"\n        return self._variables[name]\n\n\n# Global instance\n__REGISTRY__ = EmbeddingFunctionRegistry()\n\n\n# @EmbeddingFunctionRegistry.get_instance().register(name) doesn't work in 3.8\ndef register(name):\n    return __REGISTRY__.get_instance().register(name)\n\n","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/lancedb/lancedb/blob/c7b051aff7039333a3f61b79217246c27676806a/python/python/lancedb/embeddings/registry.py#L155-L191","documentation":"The embedding registry lets you define named variables (e.g. for API keys or runtime flags) via set_var. Variable names are joined with colons in the registry's name syntax, so a colon in a name would corrupt that syntax; the library rejects such names with ValueError at registration time.","triggerScenarios":"Calling registry.set_var(name, value) where the name string contains ':' (e.g. set_var('openai:key', ...)).","commonSituations":"Developers try to namespace variables like 'provider:key' or pass full 'VAR:value' strings copied from docs or env-var strings.","solutions":["Remove the colon from the variable name, e.g. use 'openai_key' or 'openai-key' instead of 'openai:key'","Keep any ':' only in the value, which is allowed","If namespacing is needed, encode it without colons, e.g. use '__' or '/' separators"],"exampleFix":"// before\nregistry.set_var(\"openai:key\", \"sk-...\")\n// after\nregistry.set_var(\"openai_key\", \"sk-...\")","handlingStrategy":"validation","validationCode":"def valid_var_name(name: str) -> bool:\n    return isinstance(name, str) and \":\" not in name and len(name) > 0\n\nif not valid_var_name(name):\n    raise ValueError(f\"Variable name '{name}' must not contain ':'\")\nregistry.set_var(name, value)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Sanitize variable names to [A-Za-z0-9_-] before registering","Never copy 'KEY:value' config strings directly as names","Use a separator like '__' for namespacing"],"tags":["python","validation","registry"],"backgroundTag":"invalid-identifier-format","analyzedSha":"c7b051aff7039333a3f61b79217246c27676806a","analyzedAt":"2026-09-08T23:42:37.579Z","contentChangedAt":"2026-09-08T23:42:37.579Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}