Skip to content

Commit d6a3e65

Browse files
committed
validate output
Signed-off-by: Sicheng Song <sicheng.song@outlook.com>
1 parent e05d8c7 commit d6a3e65

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/remote/RemoteConnectorExecutor.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,10 @@ default ModelTensorOutput executePredict(MLInput mlInput) throws IOException {
7878
} else {
7979
validateInputSchema(mlInput);
8080
preparePayloadAndInvokeRemoteModel(mlInput, tensorOutputs);
81-
validateOutputSchema(tensorOutputs);
8281
}
83-
return new ModelTensorOutput(tensorOutputs);
82+
ModelTensorOutput modelTensorOutput = new ModelTensorOutput(tensorOutputs);
83+
validateOutputSchema(modelTensorOutput);
84+
return modelTensorOutput;
8485
}
8586

8687
default void setScriptService(ScriptService scriptService) {}
@@ -163,10 +164,10 @@ private void validateInputSchema(MLInput mlInput) throws IOException {
163164
}
164165
}
165166

166-
private void validateOutputSchema(List<ModelTensors> tensorOutput) throws IOException {
167+
private void validateOutputSchema(ModelTensorOutput modelTensorOutput) throws IOException {
167168
if (getConnector().getModelInterface() != null && getConnector().getModelInterface().get("output") != null) {
168169
String schemaString = getConnector().getModelInterface().get("output");
169-
ConnectorUtils.validateSchema(schemaString, tensorOutput.toString());
170+
ConnectorUtils.validateSchema(schemaString, modelTensorOutput.toXContent(XContentFactory.jsonBuilder(), ToXContent.EMPTY_PARAMS).toString());
170171
}
171172
}
172173
}

0 commit comments

Comments
 (0)