Skip to main content
Items marked (preview) in this article are currently in public preview. This preview is provided without a service-level agreement, and we don’t recommend it for production workloads. Certain features might not be supported or might have constrained capabilities. For more information, see Supplemental Terms of Use for Microsoft Azure Previews.
Built-in evaluators provide an easy way to monitor the quality of your application’s generations. To customize your evaluations, you can create your own code-based, prompt-based, or endpoint-based evaluators. Custom evaluators let you define domain-specific quality metrics that go beyond the built-in evaluator catalog. Use a custom evaluator when you need to measure criteria unique to your application, such as brand tone, domain-specific accuracy, or output format compliance. You can create three types of custom evaluators: After you create a custom evaluator, you can add it to the evaluator catalog in your Foundry project and use it in batch evaluation runs.

Code-based evaluators

A code-based evaluator is a Python function named grade that receives two dict parameters (sample and item) and returns a float score between 0.0 and 1.0 (higher is better). In practice, all data is accessed through item:
  • Dataset evaluation: Input fields like response or ground_truth can be retrieved in the Python code like item.get("response") or item.get("ground_truth").
  • Model or agent target evaluation: To fetch generated response text, use item.get("sample", {}).get("output_text").
Currently, generated response text from a model or agent target is accessed through item.get("sample", {}).get("output_text"). This access pattern is subject to change in a future API update.
The following example scores responses based on length, preferring responses between 50 and 500 characters:
If the grade() function raises an exception or times out, the service records that item’s result as 0.0 and marks it as an error in the evaluation report. Design your function defensively — use try/except for risky operations and return a fallback score rather than letting exceptions propagate.

Supported packages and limits

Code-based evaluators run in a sandboxed Python environment with the following constraints:
  • Code size must be less than 256 KB.
  • Execution is limited to 2 minutes per grading call.
  • No network access is available at runtime.
  • Memory limit is 2 GB, disk limit is 1 GB, and CPU is limited to 2 cores.
The following third-party packages are available: The NLTK corpora punkt, stopwords, wordnet, omw-1.4, and names are preloaded.

Runtime parameters

pass_threshold and deployment_name are required as initialization parameters when you create a code-based evaluator. Even though code-based evaluators don’t call an LLM, the service API schema requires deployment_name for evaluation-run orchestration. You can pass any valid model deployment name from your project.

Prompt-based evaluators

A prompt-based evaluator uses a judge prompt template that an LLM evaluates for each item. Template variables use double curly braces (for example, {{query}}) and map to your input data fields. Prompt-based evaluators support three scoring methods:
  • Ordinal: Integer scores on a discrete scale you define (for example, 1–5). Higher is better.
  • Continuous: Float scores for fine-grained measurement on a range you define (for example, 0.0–1.0). Higher is better.
  • Binary (true/false): Boolean result for threshold-based checks.
The evaluator must return a JSON object with result and reason. The type of result matches your scoring method: an integer for ordinal, a float for continuous, or a boolean for binary. The following example prompt uses ordinal scoring (1–5) to evaluate the friendliness of a response:

Runtime parameters

Both deployment_name and threshold are required as initialization parameters when you create a prompt-based evaluator.

Endpoint-based evaluators

An endpoint-based evaluator delegates scoring to an external HTTP endpoint that you own and operate. The evaluation service calls your endpoint for each item (or batch of items), passing the mapped input data as a JSON payload. Your endpoint processes the data using any logic you choose and returns a JSON response with scores. Use an endpoint-based evaluator when you need:
  • Network access to external services or databases during scoring.
  • Proprietary models or ML pipelines hosted on your own infrastructure.
  • Complex scoring logic that exceeds the sandboxed code-based evaluator limits.
  • Integration with existing evaluation services or APIs.

How it works

  1. You deploy an HTTP endpoint that accepts POST requests with evaluation data.
  2. You create a connection in your Foundry project that stores the endpoint URL and authentication credentials.
  3. You register an endpoint-based evaluator that references the connection.
  4. When an evaluation runs, the service resolves the connection, calls your endpoint with the input data, and records the response as the evaluation result.

Endpoint request schema

The evaluation service sends a POST request to your endpoint with a JSON body containing evaluation metadata and the mapped input fields. The following table describes the fields your endpoint receives: Example request:

Endpoint response schema

The following table describes the fields your endpoint can return: Success Response: Your endpoint must return a JSON object that conforms to the standard evaluation result schema:
Failure Reponse: In case of error, your endpoint needs to return a JSON object that conforms to the following schema:

Authentication

Endpoint-based evaluators support two authentication methods through project connections:

Create the endpoint connection

Connections store the endpoint URL and authentication credentials. Create a connection using the Azure Cognitive Services management client:

API Key connection

Microsoft Entra ID connection

For Entra ID authentication, your endpoint must be configured to accept tokens issued by the project’s managed identity. This typically involves:
  • Registering an application in Microsoft Entra ID for your endpoint.
  • Enabling Easy Auth (or equivalent token validation) on your endpoint.
  • Granting the project’s managed identity an app role assignment on the target application.

Register the evaluator

After creating the connection, register an endpoint-based evaluator that references it:

Run an evaluation with an endpoint-based evaluator

Use the data_mapping field to specify which input data fields are sent to your endpoint:
The data_mapping keys become the JSON fields your endpoint receives. Map them to the columns in your evaluation dataset using {{item.<field_name>}} syntax.

Deploy your endpoint

Your evaluation endpoint can be any HTTP service that accepts POST requests and returns JSON. Common hosting options include:
  • Azure Functions: Lightweight, serverless hosting for simple scoring logic.
  • Azure App Service: Full web app hosting for complex evaluation pipelines.
  • Azure Container Apps: Container-based hosting for ML model inference.
The endpoint must respond within the evaluation service timeout (30 seconds) and return a valid JSON response for each request.

Create a custom evaluator with the SDK

Prerequisites and setup

Install the SDK and set up your client:

Create a code-based evaluator

Pass the grade() function as a string in the code_text field. Define the data_schema to declare the input fields your function expects, and the metrics to describe the score your function returns. Code-based evaluators use the continuous metric type with a range of 0.0 to 1.0. First, define the evaluator version schema:
For a complete example, see the code-based evaluator Python SDK sample.

Create a prompt-based evaluator

Pass the judge prompt in the prompt_text field. Define the data_schema to declare the input fields your prompt expects, and the metrics to describe the scoring method and range. The init_parameters declare the model deployment and threshold the evaluator needs at runtime.
For a complete example, see the prompt-based evaluator Python SDK sample.

Run an evaluation with a custom evaluator

After you create custom evaluators, use them in an evaluation run the same way you use built-in evaluators. You can include multiple evaluators in a single run. The following example runs both the code-based response_length_scorer and the prompt-based friendliness_evaluator together.

Define and run the evaluation

Get results

Poll the evaluation run until it finishes, then retrieve the per-item results and report URL.

Clean up resources

Delete a custom evaluator version and the evaluation when you no longer need them:
For more information on data source options, evaluator mappings, and advanced scenarios, see Run evaluations from the SDK. For additional examples including listing, updating, and deleting evaluators, see the evaluator catalog management Python SDK sample.

Create a custom evaluator in the portal

You can create custom evaluators directly in the Azure AI Foundry portal without writing SDK code.
  1. In your Foundry project, go to Evaluation > Evaluator catalog.
  2. Select Custom evaluator > Create.
  3. Fill in the following fields:

Use a custom evaluator in a portal evaluation

After you create a custom evaluator, use it in an evaluation run from the portal:
  1. In your Foundry project, go to Evaluation and select Create.
  2. Follow the evaluation creation wizard. On the Criteria step, select Add evaluator.
  3. Choose your custom evaluator from the evaluator catalog.
  4. Supply the required initialization parameters. For prompt-based evaluators, provide the model deployment and threshold. For code-based evaluators, provide the pass threshold.
  5. Complete the wizard and start the evaluation run.
For detailed steps on running evaluations from the portal, see Run evaluations from the portal.

Conversation-level custom evaluators

Custom evaluators can score entire conversations instead of individual turns. To enable conversation-level evaluation:
  1. Set evaluation_level="conversation" on the evaluation run
  2. Design your grade() function to expect item["messages"] as a conversation array
When running at the conversation level, the item dict receives the full conversation messages array instead of a single query/response pair. This enables you to build custom metrics that assess the entire user interaction.

Example: Session-level compliance check

This example checks whether the agent disclosed a required disclaimer at any point during the conversation:

Example: Conversation length scorer

This example scores conversations based on whether they resolved within a target number of turns: