{"record":{"id":"da2849da05e1b1ca","repo":"docling-project/docling","slug":"expected-apikservev2objectdetectionengineoptions","errorCode":null,"errorMessage":"Expected ApiKserveV2ObjectDetectionEngineOptions, got {type(options)}","messagePattern":"Expected ApiKserveV2ObjectDetectionEngineOptions, got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"docling/models/inference_engines/object_detection/factory.py","lineNumber":98,"sourceCode":"            )\n\n        return TransformersObjectDetectionEngine(\n            options=options,\n            model_config=model_config,\n            accelerator_options=accelerator_options,\n            artifacts_path=artifacts_path,\n        )\n\n    elif options.engine_type == ObjectDetectionEngineType.API_KSERVE_V2:\n        from docling.datamodel.object_detection_engine_options import (\n            ApiKserveV2ObjectDetectionEngineOptions,\n        )\n        from docling.models.inference_engines.object_detection.api_kserve_v2_engine import (\n            ApiKserveV2ObjectDetectionEngine,\n        )\n\n        if not isinstance(options, ApiKserveV2ObjectDetectionEngineOptions):\n            raise ValueError(\n                f\"Expected ApiKserveV2ObjectDetectionEngineOptions, got {type(options)}\"\n            )\n\n        return ApiKserveV2ObjectDetectionEngine(\n            enable_remote_services=enable_remote_services,\n            options=options,\n            model_config=model_config,\n            accelerator_options=accelerator_options,\n            artifacts_path=artifacts_path,\n        )\n\n    else:\n        raise ValueError(f\"Unknown engine type: {options.engine_type}\")\n","sourceCodeStart":80,"sourceCodeEnd":112,"githubUrl":"https://github.com/docling-project/docling/blob/61d76f1ff3f8428065465889f7b4577da7df704c/docling/models/inference_engines/object_detection/factory.py#L80-L112","documentation":"The factory raises ValueError when engine_type is API_KSERVE_V2 but options is not an ApiKserveV2ObjectDetectionEngineOptions instance. Because the KServe engine makes remote calls, the factory also threads enable_remote_services through, and an options/type mismatch means configuration integrity is broken.","triggerScenarios":"Setting engine_type = ObjectDetectionEngineType.API_KSERVE_V2 on options of another concrete class and calling the factory's create function.","commonSituations":"Adapting a local-engine config to a remote KServe setup by only changing the enum; deserializing persisted options with a schema that lost the concrete class; sharing one options dict across multiple engine types.","solutions":["Use ApiKserveV2ObjectDetectionEngineOptions (with url and related fields) as the options object.","Pass enable_remote_services=True from the pipeline options so the constructed engine does not immediately raise OperationNotAllowed.","Rebuild config from the Docling examples for the KServe path rather than patching an existing ONNX/Transformers config."],"exampleFix":"# before\nopts = OnnxRuntimeObjectDetectionEngineOptions()\nopts.engine_type = ObjectDetectionEngineType.API_KSERVE_V2\n\n# after\nfrom docling.datamodel.object_detection_engine_options import ApiKserveV2ObjectDetectionEngineOptions\nopts = ApiKserveV2ObjectDetectionEngineOptions(url=\"https://kserve.example.com\")","handlingStrategy":"type-guard","validationCode":"from docling.datamodel.object_detection_engine_options import ApiKserveV2ObjectDetectionEngineOptions\nassert isinstance(opts, ApiKserveV2ObjectDetectionEngineOptions), type(opts)","typeGuard":"def is_kserve_opts(o: object) -> TypeGuard[ApiKserveV2ObjectDetectionEngineOptions]:\n    return isinstance(o, ApiKserveV2ObjectDetectionEngineOptions)","tryCatchPattern":"try:\n    engine = create_object_detection_engine(options=opts, enable_remote_services=True)\nexcept ValueError as e:\n    raise ConfigurationError(str(e)) from e","preventionTips":["Pair ApiKserveV2ObjectDetectionEngineOptions with enable_remote_services=True from the start.","Add a config schema check mapping engine_type -> required options class.","Build remote-engine configs from the official examples."],"tags":["configuration","factory","type-mismatch","kserve","object-detection"],"backgroundTag":null,"analyzedSha":"61d76f1ff3f8428065465889f7b4577da7df704c","analyzedAt":"2026-08-14T23:53:18.727Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}