{"record":{"id":"45f0a8f79a3c65bd","repo":"mlflow/mlflow","slug":"object-constructor-key-not-found-in-dict","errorCode":null,"errorMessage":"'object_constructor' key not found in dict.","messagePattern":"'object_constructor' key not found in dict\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"mlflow/llama_index/serialize_objects.py","lineNumber":91,"sourceCode":"\n    This method is necessary because the `template_vars` cannot be passed directly to the\n    constructor and needs to be set on an instantiated object.\n    \"\"\"\n    if template := kwargs.pop(\"template\", None):\n        prompt_template = constructor(template)\n        for k, v in kwargs.items():\n            setattr(prompt_template, k, v)\n\n        return prompt_template\n    else:\n        raise ValueError(\n            \"'template' is a required kwargs and is not present in the prompt template kwargs.\"\n        )\n\n\ndef dict_to_object(object_representation: dict[str, Any]) -> object:\n    if \"object_constructor\" not in object_representation:\n        raise ValueError(\"'object_constructor' key not found in dict.\")\n    if \"object_kwargs\" not in object_representation:\n        raise ValueError(\"'object_kwargs' key not found in dict.\")\n\n    constructor_str = object_representation[\"object_constructor\"]\n    kwargs = object_representation[\"object_kwargs\"]\n\n    import_path, class_name = constructor_str.rsplit(\".\", 1)\n    module = importlib.import_module(import_path)\n\n    if isinstance(module, PromptTemplate):\n        return _construct_prompt_template_object(module, kwargs)\n    else:\n        object_class = getattr(module, class_name)\n\n        # Many embeddings model accepts parameter `model`, while BaseEmbedding accepts `model_name`.\n        # Both parameters will be serialized as kwargs, but passing both to the constructor will\n        # raise duplicate argument error. Some class like OpenAIEmbedding handles this in its\n        # constructor, but not all integrations do. Therefore, we have to handle it here.","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/mlflow/mlflow/blob/6a27f2decc0b76eb1b54af31849784addb357dbc/mlflow/llama_index/serialize_objects.py#L73-L109","documentation":"dict_to_object requires the serialized dict to have an 'object_constructor' key holding the dotted import path of the class to instantiate. When that key is absent it cannot determine what to construct and raises ValueError.","triggerScenarios":"Passing a dict that is not valid MLflow LlamaIndex serialization output to dict_to_object, e.g. {'object_kwargs': {...}} or an arbitrary config dict.","commonSituations":"Loading a JSON file created by a different tool or older MLflow version, hand-authoring serialized objects, or a corrupted/truncated serialization file.","solutions":["Ensure the dict contains 'object_constructor' (dotted path like 'llama_index.core.prompts.PromptTemplate')","Re-generate the dict via mlflow.llama_index.object_to_dict on the original object","Check the JSON source for truncation or schema drift between versions"],"exampleFix":"// before\nobj = dict_to_object({\"object_kwargs\": {\"template\": \"q: {q}\"}})  # ValueError\n// after\nobj = dict_to_object({\"object_constructor\": \"llama_index.core.prompts.PromptTemplate\",\n                      \"object_kwargs\": {\"template\": \"q: {q}\"}})","handlingStrategy":"validation","validationCode":"if \"object_constructor\" not in d:\n    raise KeyError(\"object_constructor missing from serialized object\")","typeGuard":"def is_valid_serialized_object(d: object) -> bool:\n    return isinstance(d, dict) and \"object_constructor\" in d and \"object_kwargs\" in d","tryCatchPattern":"try:\n    obj = dict_to_object(d)\nexcept ValueError as e:\n    obj = None\n    logger.warning(\"Malformed serialized object: %s\", e)","preventionTips":["Only pass dicts produced by object_to_object/dict serialization utilities","Validate both required keys before deserialization","Checksum/version-stamp serialized files so old formats are detected"],"tags":["llama-index","serialization","missing-key","dict"],"backgroundTag":"missing-required-key","analyzedSha":"6a27f2decc0b76eb1b54af31849784addb357dbc","analyzedAt":"2026-08-29T20:54:51.419Z","schemaVersion":2},"datasetVersion":"2026-08-29T22:17:34.462Z"}