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.
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 namedgrade 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
responseorground_truthcan be retrieved in the Python code likeitem.get("response")oritem.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.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 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.
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
Bothdeployment_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
- You deploy an HTTP endpoint that accepts POST requests with evaluation data.
- You create a connection in your Foundry project that stores the endpoint URL and authentication credentials.
- You register an endpoint-based evaluator that references the connection.
- 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:
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
- 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 thedata_mapping field to specify which input data fields are sent to your endpoint:
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.
Create a custom evaluator with the SDK
Prerequisites and setup
Install the SDK and set up your client:Create a code-based evaluator
Pass thegrade() 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:
Create a prompt-based evaluator
Pass the judge prompt in theprompt_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.
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-basedresponse_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:Create a custom evaluator in the portal
You can create custom evaluators directly in the Azure AI Foundry portal without writing SDK code.- In your Foundry project, go to Evaluation > Evaluator catalog.
- Select Custom evaluator > Create.
- 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:- In your Foundry project, go to Evaluation and select Create.
- Follow the evaluation creation wizard. On the Criteria step, select Add evaluator.
- Choose your custom evaluator from the evaluator catalog.
- Supply the required initialization parameters. For prompt-based evaluators, provide the model deployment and threshold. For code-based evaluators, provide the pass threshold.
- Complete the wizard and start the evaluation run.
Conversation-level custom evaluators
Custom evaluators can score entire conversations instead of individual turns. To enable conversation-level evaluation:- Set
evaluation_level="conversation"on the evaluation run - Design your
grade()function to expectitem["messages"]as a conversation array
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.