# This file was auto-generated by Fern from our API Definition.

import typing

from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ...core.request_options import RequestOptions
from ..commons.types.evaluation_rule_filter import EvaluationRuleFilter
from ..commons.types.evaluation_rule_mapping import EvaluationRuleMapping
from ..commons.types.evaluation_rule_target import EvaluationRuleTarget
from .raw_client import AsyncRawEvaluationRulesClient, RawEvaluationRulesClient
from .types.create_evaluation_rule_request import CreateEvaluationRuleRequest
from .types.delete_evaluation_rule_response import DeleteEvaluationRuleResponse
from .types.evaluation_rule import EvaluationRule
from .types.evaluation_rule_evaluator_reference import EvaluationRuleEvaluatorReference
from .types.evaluation_rules import EvaluationRules
from .types.readable_evaluation_rule import ReadableEvaluationRule

# this is used as the default value for optional parameters
OMIT = typing.cast(typing.Any, ...)


class EvaluationRulesClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawEvaluationRulesClient(client_wrapper=client_wrapper)

    @property
    def with_raw_response(self) -> RawEvaluationRulesClient:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        RawEvaluationRulesClient
        """
        return self._raw_client

    def create(
        self,
        *,
        request: CreateEvaluationRuleRequest,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> EvaluationRule:
        """
        Create an evaluation rule.

        An evaluation rule defines **what** incoming data should be evaluated and **how prompt variables should be populated** from that data.

        Use this resource after choosing an evaluator from the evaluator endpoints.

        Key rules:
        - `name` must be unique within the project for public evaluation rules
        - `target` must be `observation` or `experiment`
        - `evaluator.name` + `evaluator.scope` must identify an existing evaluator family returned by the evaluator endpoints
        - Langfuse resolves that family to its latest version before saving the evaluation rule
        - for `target=experiment`, use dataset `id` values from `GET /api/public/v2/datasets` when filtering by `datasetId`
        - for `llm_as_judge` evaluators, every evaluator prompt variable must be mapped exactly once
        - for `code` evaluators, Langfuse uses the fixed code runtime mapping; omit `mapping` in create and update requests
        - for user-provided `llm_as_judge` mappings, `expected_output` and `experiment_item_metadata` are only valid for `target=experiment`
        - if `enabled=true`, Langfuse validates that the referenced evaluator can currently run
        - at most 50 evaluation rules can be effectively active in one project at the same time

        If an evaluation rule with the same `name` already exists in the project, the API returns `409`.
        In that case, update the existing resource with `PATCH /api/public/unstable/evaluation-rules/{evaluationRuleId}` instead of creating a second one.

        If enabling this resource would exceed the 50-active limit, the API also returns `409`.
        In that case, disable or pause another active evaluation rule before enabling a new one.

        Current scope:
        - evaluation rules are live-ingestion rules only
        - they do not trigger historical backfills

        Recovery guidance:
        - `400 invalid_filter_value`: fix the filter `column` or `value` using `details.column`, `details.invalidValues`, and `details.allowedValues`
        - `400 invalid_filter_value` with `details.column=datasetId`: call `GET /api/public/v2/datasets`, then retry with dataset `id` values from that response
        - `400 missing_variable_mapping`: for `llm_as_judge` evaluators, fetch the evaluator again and make sure every variable in `variables` appears exactly once in `mapping`
        - `400 duplicate_variable_mapping`: remove repeated mappings for the same variable
        - `400 invalid_variable_mapping`: for `llm_as_judge`, switch to a valid `source` for the selected `target`, or fix the variable name
        - `400 invalid_json_path`: remove or correct the `jsonPath`
        - `422 evaluator_preflight_failed`: the selected evaluator cannot run with the resolved model configuration. Fix the evaluator/default model setup, then retry the create request.

        Parameters
        ----------
        request : CreateEvaluationRuleRequest

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        EvaluationRule

        Examples
        --------
        from langfuse import LangfuseAPI
        from langfuse.unstable.commons import (
            EvaluationRuleFilter_StringOptions,
            EvaluationRuleMapping,
            EvaluationRuleMappingSource,
            EvaluationRuleOptionsFilterOperator,
            EvaluationRuleTarget,
            EvaluatorScope,
        )
        from langfuse.unstable.evaluation_rules import (
            CreateLlmAsJudgeEvaluationRuleRequest,
            LlmAsJudgeEvaluationRuleEvaluatorReference,
            LlmAsJudgeEvaluatorType,
        )

        client = LangfuseAPI(
            x_langfuse_sdk_name="YOUR_X_LANGFUSE_SDK_NAME",
            x_langfuse_sdk_version="YOUR_X_LANGFUSE_SDK_VERSION",
            x_langfuse_public_key="YOUR_X_LANGFUSE_PUBLIC_KEY",
            username="YOUR_USERNAME",
            password="YOUR_PASSWORD",
            base_url="https://yourhost.com/path/to/api",
        )
        client.unstable.evaluation_rules.create(
            request=CreateLlmAsJudgeEvaluationRuleRequest(
                name="answer-correctness-live",
                evaluator=LlmAsJudgeEvaluationRuleEvaluatorReference(
                    name="answer-correctness",
                    scope=EvaluatorScope.PROJECT,
                    type=LlmAsJudgeEvaluatorType.LLM_AS_JUDGE,
                ),
                target=EvaluationRuleTarget.OBSERVATION,
                enabled=True,
                sampling=1.0,
                filter=[
                    EvaluationRuleFilter_StringOptions(
                        column="type",
                        operator=EvaluationRuleOptionsFilterOperator.ANY_OF,
                        value=["GENERATION"],
                    )
                ],
                mapping=[
                    EvaluationRuleMapping(
                        variable="input",
                        source=EvaluationRuleMappingSource.INPUT,
                    ),
                    EvaluationRuleMapping(
                        variable="output",
                        source=EvaluationRuleMappingSource.OUTPUT,
                    ),
                ],
            ),
        )
        """
        _response = self._raw_client.create(
            request=request, request_options=request_options
        )
        return _response.data

    def list(
        self,
        *,
        page: typing.Optional[int] = None,
        limit: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> EvaluationRules:
        """
        List evaluation rules in the authenticated project.

        This includes legacy `trace` and `dataset` rules so they can be inspected and migrated to v4 rules. Legacy rules are read-only through this API; create, update, and delete continue to support only `observation` and `experiment` rules.

        Parameters
        ----------
        page : typing.Optional[int]
            1-based page number. Defaults to `1`.

        limit : typing.Optional[int]
            Maximum number of items per page. Defaults to `50`.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        EvaluationRules

        Examples
        --------
        from langfuse import LangfuseAPI

        client = LangfuseAPI(
            x_langfuse_sdk_name="YOUR_X_LANGFUSE_SDK_NAME",
            x_langfuse_sdk_version="YOUR_X_LANGFUSE_SDK_VERSION",
            x_langfuse_public_key="YOUR_X_LANGFUSE_PUBLIC_KEY",
            username="YOUR_USERNAME",
            password="YOUR_PASSWORD",
            base_url="https://yourhost.com/path/to/api",
        )
        client.unstable.evaluation_rules.list()
        """
        _response = self._raw_client.list(
            page=page, limit=limit, request_options=request_options
        )
        return _response.data

    def get(
        self,
        evaluation_rule_id: str,
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ReadableEvaluationRule:
        """
        Get one evaluation rule by its identifier.

        Use this endpoint to inspect the current evaluator, target, mapping, filters, execution timing, and effective runtime status. Legacy `trace` and `dataset` rules are returned for migration and are read-only through this API.

        Parameters
        ----------
        evaluation_rule_id : str
            Evaluation rule identifier returned by the evaluation rule endpoints.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        ReadableEvaluationRule

        Examples
        --------
        from langfuse import LangfuseAPI

        client = LangfuseAPI(
            x_langfuse_sdk_name="YOUR_X_LANGFUSE_SDK_NAME",
            x_langfuse_sdk_version="YOUR_X_LANGFUSE_SDK_VERSION",
            x_langfuse_public_key="YOUR_X_LANGFUSE_PUBLIC_KEY",
            username="YOUR_USERNAME",
            password="YOUR_PASSWORD",
            base_url="https://yourhost.com/path/to/api",
        )
        client.unstable.evaluation_rules.get(
            evaluation_rule_id="evaluationRuleId",
        )
        """
        _response = self._raw_client.get(
            evaluation_rule_id, request_options=request_options
        )
        return _response.data

    def update(
        self,
        evaluation_rule_id: str,
        *,
        name: typing.Optional[str] = OMIT,
        evaluator: typing.Optional[EvaluationRuleEvaluatorReference] = OMIT,
        target: typing.Optional[EvaluationRuleTarget] = OMIT,
        enabled: typing.Optional[bool] = OMIT,
        sampling: typing.Optional[float] = OMIT,
        filter: typing.Optional[typing.Sequence[EvaluationRuleFilter]] = OMIT,
        mapping: typing.Optional[typing.Sequence[EvaluationRuleMapping]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> EvaluationRule:
        """
        Update an evaluation rule.

        Typical uses:
        - enable or disable live execution
        - switch to another evaluator
        - adjust sampling
        - change filters
        - update LLM-as-judge variable mappings

        Important behavior:
        - provide only the fields you want to change
        - if you provide `evaluator`, Langfuse resolves that evaluator family to its latest version before saving
        - changing `target`, `filter`, or an LLM-as-judge `mapping` must still produce a valid target-specific configuration
        - if you change `target` for an LLM-as-judge rule, also send a compatible `filter` and `mapping` in the same request unless the existing ones are still valid for the new target
        - for `code` evaluator rules, omit `mapping`; Langfuse stores the fixed code runtime mapping automatically
        - if the resulting config is enabled, Langfuse re-validates that the selected evaluator can run
        - if the update would move a non-active evaluation rule into the active state and the project already has 50 active evaluation rules, the API returns `409`

        Recovery guidance:
        - if an LLM-as-judge update fails with `missing_variable_mapping` or `invalid_variable_mapping` after changing `evaluator` or `target`, resend the request with a complete new `mapping`
        - if the update fails with `invalid_filter_value` after changing `target`, resend the request with a target-compatible `filter`

        Parameters
        ----------
        evaluation_rule_id : str
            Evaluation rule identifier.

        name : typing.Optional[str]
            Updated deployment name.

        evaluator : typing.Optional[EvaluationRuleEvaluatorReference]
            Updated evaluator family.

            Langfuse resolves the provided evaluator family to its latest version before saving the rule.
            A rule's evaluator type cannot be changed: provide `name` and `scope` for an evaluator family of the rule's current type. To use a different evaluator type, create a new rule.

        target : typing.Optional[EvaluationRuleTarget]
            Updated target object type.

        enabled : typing.Optional[bool]
            Updated desired enabled state.

        sampling : typing.Optional[float]
            Updated sampling fraction.

        filter : typing.Optional[typing.Sequence[EvaluationRuleFilter]]
            Updated filter list.

            For `target=experiment`, `column=datasetId` expects dataset `id` values from `GET /api/public/v2/datasets`, not dataset names.

        mapping : typing.Optional[typing.Sequence[EvaluationRuleMapping]]
            Updated LLM-as-judge variable mappings.

            Do not send this field for code evaluator rules. Langfuse stores the fixed code runtime mapping automatically and returns it in the response.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        EvaluationRule

        Examples
        --------
        from langfuse import LangfuseAPI

        client = LangfuseAPI(
            x_langfuse_sdk_name="YOUR_X_LANGFUSE_SDK_NAME",
            x_langfuse_sdk_version="YOUR_X_LANGFUSE_SDK_VERSION",
            x_langfuse_public_key="YOUR_X_LANGFUSE_PUBLIC_KEY",
            username="YOUR_USERNAME",
            password="YOUR_PASSWORD",
            base_url="https://yourhost.com/path/to/api",
        )
        client.unstable.evaluation_rules.update(
            evaluation_rule_id="evaluationRuleId",
        )
        """
        _response = self._raw_client.update(
            evaluation_rule_id,
            name=name,
            evaluator=evaluator,
            target=target,
            enabled=enabled,
            sampling=sampling,
            filter=filter,
            mapping=mapping,
            request_options=request_options,
        )
        return _response.data

    def delete(
        self,
        evaluation_rule_id: str,
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DeleteEvaluationRuleResponse:
        """
        Delete an evaluation rule.

        This removes the live-ingestion rule only. It does not delete the referenced evaluator.

        Parameters
        ----------
        evaluation_rule_id : str
            Evaluation rule identifier.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        DeleteEvaluationRuleResponse

        Examples
        --------
        from langfuse import LangfuseAPI

        client = LangfuseAPI(
            x_langfuse_sdk_name="YOUR_X_LANGFUSE_SDK_NAME",
            x_langfuse_sdk_version="YOUR_X_LANGFUSE_SDK_VERSION",
            x_langfuse_public_key="YOUR_X_LANGFUSE_PUBLIC_KEY",
            username="YOUR_USERNAME",
            password="YOUR_PASSWORD",
            base_url="https://yourhost.com/path/to/api",
        )
        client.unstable.evaluation_rules.delete(
            evaluation_rule_id="evaluationRuleId",
        )
        """
        _response = self._raw_client.delete(
            evaluation_rule_id, request_options=request_options
        )
        return _response.data


class AsyncEvaluationRulesClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawEvaluationRulesClient(client_wrapper=client_wrapper)

    @property
    def with_raw_response(self) -> AsyncRawEvaluationRulesClient:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        AsyncRawEvaluationRulesClient
        """
        return self._raw_client

    async def create(
        self,
        *,
        request: CreateEvaluationRuleRequest,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> EvaluationRule:
        """
        Create an evaluation rule.

        An evaluation rule defines **what** incoming data should be evaluated and **how prompt variables should be populated** from that data.

        Use this resource after choosing an evaluator from the evaluator endpoints.

        Key rules:
        - `name` must be unique within the project for public evaluation rules
        - `target` must be `observation` or `experiment`
        - `evaluator.name` + `evaluator.scope` must identify an existing evaluator family returned by the evaluator endpoints
        - Langfuse resolves that family to its latest version before saving the evaluation rule
        - for `target=experiment`, use dataset `id` values from `GET /api/public/v2/datasets` when filtering by `datasetId`
        - for `llm_as_judge` evaluators, every evaluator prompt variable must be mapped exactly once
        - for `code` evaluators, Langfuse uses the fixed code runtime mapping; omit `mapping` in create and update requests
        - for user-provided `llm_as_judge` mappings, `expected_output` and `experiment_item_metadata` are only valid for `target=experiment`
        - if `enabled=true`, Langfuse validates that the referenced evaluator can currently run
        - at most 50 evaluation rules can be effectively active in one project at the same time

        If an evaluation rule with the same `name` already exists in the project, the API returns `409`.
        In that case, update the existing resource with `PATCH /api/public/unstable/evaluation-rules/{evaluationRuleId}` instead of creating a second one.

        If enabling this resource would exceed the 50-active limit, the API also returns `409`.
        In that case, disable or pause another active evaluation rule before enabling a new one.

        Current scope:
        - evaluation rules are live-ingestion rules only
        - they do not trigger historical backfills

        Recovery guidance:
        - `400 invalid_filter_value`: fix the filter `column` or `value` using `details.column`, `details.invalidValues`, and `details.allowedValues`
        - `400 invalid_filter_value` with `details.column=datasetId`: call `GET /api/public/v2/datasets`, then retry with dataset `id` values from that response
        - `400 missing_variable_mapping`: for `llm_as_judge` evaluators, fetch the evaluator again and make sure every variable in `variables` appears exactly once in `mapping`
        - `400 duplicate_variable_mapping`: remove repeated mappings for the same variable
        - `400 invalid_variable_mapping`: for `llm_as_judge`, switch to a valid `source` for the selected `target`, or fix the variable name
        - `400 invalid_json_path`: remove or correct the `jsonPath`
        - `422 evaluator_preflight_failed`: the selected evaluator cannot run with the resolved model configuration. Fix the evaluator/default model setup, then retry the create request.

        Parameters
        ----------
        request : CreateEvaluationRuleRequest

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        EvaluationRule

        Examples
        --------
        import asyncio

        from langfuse import AsyncLangfuseAPI
        from langfuse.unstable.commons import (
            EvaluationRuleFilter_StringOptions,
            EvaluationRuleMapping,
            EvaluationRuleMappingSource,
            EvaluationRuleOptionsFilterOperator,
            EvaluationRuleTarget,
            EvaluatorScope,
        )
        from langfuse.unstable.evaluation_rules import (
            CreateLlmAsJudgeEvaluationRuleRequest,
            LlmAsJudgeEvaluationRuleEvaluatorReference,
            LlmAsJudgeEvaluatorType,
        )

        client = AsyncLangfuseAPI(
            x_langfuse_sdk_name="YOUR_X_LANGFUSE_SDK_NAME",
            x_langfuse_sdk_version="YOUR_X_LANGFUSE_SDK_VERSION",
            x_langfuse_public_key="YOUR_X_LANGFUSE_PUBLIC_KEY",
            username="YOUR_USERNAME",
            password="YOUR_PASSWORD",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.unstable.evaluation_rules.create(
                request=CreateLlmAsJudgeEvaluationRuleRequest(
                    name="answer-correctness-live",
                    evaluator=LlmAsJudgeEvaluationRuleEvaluatorReference(
                        name="answer-correctness",
                        scope=EvaluatorScope.PROJECT,
                        type=LlmAsJudgeEvaluatorType.LLM_AS_JUDGE,
                    ),
                    target=EvaluationRuleTarget.OBSERVATION,
                    enabled=True,
                    sampling=1.0,
                    filter=[
                        EvaluationRuleFilter_StringOptions(
                            column="type",
                            operator=EvaluationRuleOptionsFilterOperator.ANY_OF,
                            value=["GENERATION"],
                        )
                    ],
                    mapping=[
                        EvaluationRuleMapping(
                            variable="input",
                            source=EvaluationRuleMappingSource.INPUT,
                        ),
                        EvaluationRuleMapping(
                            variable="output",
                            source=EvaluationRuleMappingSource.OUTPUT,
                        ),
                    ],
                ),
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create(
            request=request, request_options=request_options
        )
        return _response.data

    async def list(
        self,
        *,
        page: typing.Optional[int] = None,
        limit: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> EvaluationRules:
        """
        List evaluation rules in the authenticated project.

        This includes legacy `trace` and `dataset` rules so they can be inspected and migrated to v4 rules. Legacy rules are read-only through this API; create, update, and delete continue to support only `observation` and `experiment` rules.

        Parameters
        ----------
        page : typing.Optional[int]
            1-based page number. Defaults to `1`.

        limit : typing.Optional[int]
            Maximum number of items per page. Defaults to `50`.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        EvaluationRules

        Examples
        --------
        import asyncio

        from langfuse import AsyncLangfuseAPI

        client = AsyncLangfuseAPI(
            x_langfuse_sdk_name="YOUR_X_LANGFUSE_SDK_NAME",
            x_langfuse_sdk_version="YOUR_X_LANGFUSE_SDK_VERSION",
            x_langfuse_public_key="YOUR_X_LANGFUSE_PUBLIC_KEY",
            username="YOUR_USERNAME",
            password="YOUR_PASSWORD",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.unstable.evaluation_rules.list()


        asyncio.run(main())
        """
        _response = await self._raw_client.list(
            page=page, limit=limit, request_options=request_options
        )
        return _response.data

    async def get(
        self,
        evaluation_rule_id: str,
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ReadableEvaluationRule:
        """
        Get one evaluation rule by its identifier.

        Use this endpoint to inspect the current evaluator, target, mapping, filters, execution timing, and effective runtime status. Legacy `trace` and `dataset` rules are returned for migration and are read-only through this API.

        Parameters
        ----------
        evaluation_rule_id : str
            Evaluation rule identifier returned by the evaluation rule endpoints.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        ReadableEvaluationRule

        Examples
        --------
        import asyncio

        from langfuse import AsyncLangfuseAPI

        client = AsyncLangfuseAPI(
            x_langfuse_sdk_name="YOUR_X_LANGFUSE_SDK_NAME",
            x_langfuse_sdk_version="YOUR_X_LANGFUSE_SDK_VERSION",
            x_langfuse_public_key="YOUR_X_LANGFUSE_PUBLIC_KEY",
            username="YOUR_USERNAME",
            password="YOUR_PASSWORD",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.unstable.evaluation_rules.get(
                evaluation_rule_id="evaluationRuleId",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get(
            evaluation_rule_id, request_options=request_options
        )
        return _response.data

    async def update(
        self,
        evaluation_rule_id: str,
        *,
        name: typing.Optional[str] = OMIT,
        evaluator: typing.Optional[EvaluationRuleEvaluatorReference] = OMIT,
        target: typing.Optional[EvaluationRuleTarget] = OMIT,
        enabled: typing.Optional[bool] = OMIT,
        sampling: typing.Optional[float] = OMIT,
        filter: typing.Optional[typing.Sequence[EvaluationRuleFilter]] = OMIT,
        mapping: typing.Optional[typing.Sequence[EvaluationRuleMapping]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> EvaluationRule:
        """
        Update an evaluation rule.

        Typical uses:
        - enable or disable live execution
        - switch to another evaluator
        - adjust sampling
        - change filters
        - update LLM-as-judge variable mappings

        Important behavior:
        - provide only the fields you want to change
        - if you provide `evaluator`, Langfuse resolves that evaluator family to its latest version before saving
        - changing `target`, `filter`, or an LLM-as-judge `mapping` must still produce a valid target-specific configuration
        - if you change `target` for an LLM-as-judge rule, also send a compatible `filter` and `mapping` in the same request unless the existing ones are still valid for the new target
        - for `code` evaluator rules, omit `mapping`; Langfuse stores the fixed code runtime mapping automatically
        - if the resulting config is enabled, Langfuse re-validates that the selected evaluator can run
        - if the update would move a non-active evaluation rule into the active state and the project already has 50 active evaluation rules, the API returns `409`

        Recovery guidance:
        - if an LLM-as-judge update fails with `missing_variable_mapping` or `invalid_variable_mapping` after changing `evaluator` or `target`, resend the request with a complete new `mapping`
        - if the update fails with `invalid_filter_value` after changing `target`, resend the request with a target-compatible `filter`

        Parameters
        ----------
        evaluation_rule_id : str
            Evaluation rule identifier.

        name : typing.Optional[str]
            Updated deployment name.

        evaluator : typing.Optional[EvaluationRuleEvaluatorReference]
            Updated evaluator family.

            Langfuse resolves the provided evaluator family to its latest version before saving the rule.
            A rule's evaluator type cannot be changed: provide `name` and `scope` for an evaluator family of the rule's current type. To use a different evaluator type, create a new rule.

        target : typing.Optional[EvaluationRuleTarget]
            Updated target object type.

        enabled : typing.Optional[bool]
            Updated desired enabled state.

        sampling : typing.Optional[float]
            Updated sampling fraction.

        filter : typing.Optional[typing.Sequence[EvaluationRuleFilter]]
            Updated filter list.

            For `target=experiment`, `column=datasetId` expects dataset `id` values from `GET /api/public/v2/datasets`, not dataset names.

        mapping : typing.Optional[typing.Sequence[EvaluationRuleMapping]]
            Updated LLM-as-judge variable mappings.

            Do not send this field for code evaluator rules. Langfuse stores the fixed code runtime mapping automatically and returns it in the response.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        EvaluationRule

        Examples
        --------
        import asyncio

        from langfuse import AsyncLangfuseAPI

        client = AsyncLangfuseAPI(
            x_langfuse_sdk_name="YOUR_X_LANGFUSE_SDK_NAME",
            x_langfuse_sdk_version="YOUR_X_LANGFUSE_SDK_VERSION",
            x_langfuse_public_key="YOUR_X_LANGFUSE_PUBLIC_KEY",
            username="YOUR_USERNAME",
            password="YOUR_PASSWORD",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.unstable.evaluation_rules.update(
                evaluation_rule_id="evaluationRuleId",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update(
            evaluation_rule_id,
            name=name,
            evaluator=evaluator,
            target=target,
            enabled=enabled,
            sampling=sampling,
            filter=filter,
            mapping=mapping,
            request_options=request_options,
        )
        return _response.data

    async def delete(
        self,
        evaluation_rule_id: str,
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DeleteEvaluationRuleResponse:
        """
        Delete an evaluation rule.

        This removes the live-ingestion rule only. It does not delete the referenced evaluator.

        Parameters
        ----------
        evaluation_rule_id : str
            Evaluation rule identifier.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        DeleteEvaluationRuleResponse

        Examples
        --------
        import asyncio

        from langfuse import AsyncLangfuseAPI

        client = AsyncLangfuseAPI(
            x_langfuse_sdk_name="YOUR_X_LANGFUSE_SDK_NAME",
            x_langfuse_sdk_version="YOUR_X_LANGFUSE_SDK_VERSION",
            x_langfuse_public_key="YOUR_X_LANGFUSE_PUBLIC_KEY",
            username="YOUR_USERNAME",
            password="YOUR_PASSWORD",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.unstable.evaluation_rules.delete(
                evaluation_rule_id="evaluationRuleId",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.delete(
            evaluation_rule_id, request_options=request_options
        )
        return _response.data
