{"record":{"id":"a4290263cc7caf48","repo":"mlflow/mlflow","slug":"invalid-parameter-value-a42902","errorCode":"INVALID_PARAMETER_VALUE","errorMessage":"Dependencies schema should be set only once to the callback.","messagePattern":"Dependencies schema should be set only once to the callback\\.","errorType":"error_code","errorClass":"MlflowException","httpStatus":400,"severity":"error","filePath":"mlflow/dspy/callback.py","lineNumber":76,"sourceCode":"        # call_id: (LiveSpan, OTel token)\n        self._call_id_to_span: dict[str, SpanWithToken] = {}\n        self._call_id_to_module: dict[str, Any] = {}\n\n        ###### state management for optimization process ######\n        # The current callback logic assumes there is no optimization running in parallel.\n        # The state management may not work when multiple optimizations are running in parallel.\n        # optimizer_stack_level is used to determine if the callback is called within compile\n        # we cannot use boolean flag because the callback can be nested\n        self.optimizer_stack_level = 0\n        # call_id: (key, step)\n        self._call_id_to_metric_key: dict[str, tuple[str, int]] = {}\n        self._evaluation_counter = defaultdict(int)\n        self._disabled_eval_call_ids = set()\n        self._eval_runs_started: set[str] = set()\n\n    def set_dependencies_schema(self, dependencies_schema: dict[str, Any]):\n        if self._dependencies_schema:\n            raise MlflowException(\n                \"Dependencies schema should be set only once to the callback.\",\n                error_code=MlflowException.INVALID_PARAMETER_VALUE,\n            )\n        self._dependencies_schema = dependencies_schema\n\n    @skip_if_trace_disabled\n    def on_module_start(self, call_id: str, instance: Any, inputs: dict[str, Any]):\n        span_type = self._get_span_type_for_module(instance)\n        attributes = self._get_span_attribute_for_module(instance)\n\n        # The __call__ method of dspy.Module has a signature of (self, *args, **kwargs),\n        # while all built-in modules only accepts keyword arguments. To avoid recording\n        # empty \"args\" key in the inputs, we remove it if it's empty.\n        if \"args\" in inputs and not inputs[\"args\"]:\n            inputs.pop(\"args\")\n\n        self._start_span(\n            call_id,","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/mlflow/mlflow/blob/6a27f2decc0b76eb1b54af31849784addb357dbc/mlflow/dspy/callback.py#L58-L94","documentation":"MLflow's DSPy callback stores a single dependencies schema used to enrich traces. Calling set_dependencies_schema() more than once on the same callback instance would silently overwrite tracing context, so MLflow raises INVALID_PARAMETER_VALUE on the second call.","triggerScenarios":"Invoking mlflow.dspy.set_dependencies_schema (via _set_dependency_schema_to_tracer) twice within one trace/session — e.g. calling it in both an initialization routine and a per-request handler with the same tracer/callback.","commonSituations":"A web app calls it at module import and again per request; a test suite reuses a tracer fixture across tests; framework autotuning re-invokes setup code on hot reload.","solutions":["Call set_dependencies_schema only once per callback/tracer lifecycle (e.g. at app startup)","Check whether the schema is already set before calling, or use a module-level 'initialized' flag","Create a fresh callback instance if a new schema truly must be installed","Remove duplicate invocations in per-request code paths"],"exampleFix":"// before\ndef handler(req):\n    mlflow.dspy.set_dependencies_schema(schema)  # called every request\n// after\ninit_schema():\n    mlflow.dspy.set_dependencies_schema(schema)\ndef handler(req):\n    pass  # schema already installed at startup","handlingStrategy":"validation","validationCode":"_schema_installed = False\n\ndef install_schema(schema):\n    global _schema_installed\n    if _schema_installed:\n        return\n    mlflow.dspy.set_dependencies_schema(schema)\n    _schema_installed = True","typeGuard":null,"tryCatchPattern":"try:\n    callback.set_dependencies_schema(schema)\nexcept MlflowException as e:\n    if 'only once' in str(e):\n        logger.debug('schema already set; skipping')\n    else:\n        raise","preventionTips":["Install the schema once at application startup, not per request","Guard with an idempotency flag in shared/framework code","Reset callback state between tests if reusing tracer fixtures"],"tags":["mlflow","dspy","tracing","configuration"],"backgroundTag":"double-initialization","analyzedSha":"6a27f2decc0b76eb1b54af31849784addb357dbc","analyzedAt":"2026-08-29T20:54:51.419Z","schemaVersion":2},"datasetVersion":"2026-08-29T22:17:34.462Z"}