Skip to content

[ML] CustomService adding template validation prior to request flow #129591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 18, 2025

Conversation

jonathan-buttner
Copy link
Contributor

@jonathan-buttner jonathan-buttner commented Jun 17, 2025

This PR addresses the feedback item from the original PR: #127939

This PR adds some additional validation logic prior to the typical test request validation. This addresses the validation error being nested a couple levels deep when the traditional validation is executed.

The error would also be caught in the normal request validation logic but it is nested a few levels. This change performs the initial validation for schema before making an actual request.

Comments:
#127939 (comment)

Example error after this change

{
    "error": {
        "root_cause": [
            {
                "type": "validation_exception",
                "reason": "Validation Failed: 1: Failed to validate model configuration: Found placeholder [${api_keys}] in field [header.Authorization] after replacement call, please check that all templates have a corresponding field definition.;"
            }
        ],
        "type": "validation_exception",
        "reason": "Validation Failed: 1: Failed to validate model configuration: Found placeholder [${api_keys}] in field [header.Authorization] after replacement call, please check that all templates have a corresponding field definition.;"
    },
    "status": 400
}

@jonathan-buttner jonathan-buttner added >refactoring :ml Machine learning Team:ML Meta label for the ML team auto-backport Automatically create backport pull requests when merged v8.19.0 v9.1.0 labels Jun 17, 2025
@jonathan-buttner jonathan-buttner marked this pull request as ready for review June 18, 2025 14:23
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/ml-core (Team:ML)

Copy link
Member

@davidkyle davidkyle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Definitly an improvement, this change should make it much easier to configure a custom service


try {
new CustomRequest(query, List.of("test input"), model).createHttpRequest();
} catch (Exception e) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a more specific exception to catch, perhaps define a new exception class CustomServiceSubsitutionException extends ElasticsearchException and throw that in ValidatingSubstitutor

@@ -94,12 +95,32 @@ public void parseRequestConfig(
throwIfNotEmptyMap(serviceSettingsMap, NAME);
throwIfNotEmptyMap(taskSettingsMap, NAME);

validateConfiguration(model);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@jonathan-buttner jonathan-buttner enabled auto-merge (squash) June 18, 2025 17:10
@jonathan-buttner jonathan-buttner enabled auto-merge (squash) June 18, 2025 19:27
@jonathan-buttner jonathan-buttner merged commit 2e566c9 into elastic:main Jun 18, 2025
27 checks passed
@elasticsearchmachine
Copy link
Collaborator

💚 Backport successful

Status Branch Result
8.19

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Automatically create backport pull requests when merged :ml Machine learning >refactoring Team:ML Meta label for the ML team v8.19.0 v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants