Skip to content

Commit 72ec437

Browse files
committed
Fix: Return 'invalid_prompt' error type for invalid token IDs
RVT (ROCm Validation Tool) Spec 2.9 requires POST /v1/completions with an integer-array prompt to reject invalid token IDs with HTTP 400 and error.type "invalid_prompt". Previously, invalid token IDs correctly returned HTTP 400 but used error.type "invalid_request_error" instead of the spec-required "invalid_prompt". Changes: - Add ERROR_TYPE_INVALID_PROMPT to enum error_type (server-common.h) - Map it to "invalid_prompt" / HTTP 400 (server-common.cpp) - Use it for range + type validation errors (server-context.cpp) Invalid token types now properly rejected: - Out-of-vocabulary (t >= n_vocab) - Negative values (t < -1) - LLAMA_TOKEN_NULL (-1) without valid media chunk - Non-integer JSON types (float, string, null, boolean)
1 parent 03d2068 commit 72ec437

3 files changed

Lines changed: 7 additions & 2 deletions

File tree

tools/server/server-common.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ json format_error_response(const std::string & message, const enum error_type ty
5252
type_str = "exceed_context_size_error";
5353
code = 400;
5454
break;
55+
case ERROR_TYPE_INVALID_PROMPT:
56+
type_str = "invalid_prompt";
57+
code = 400;
58+
break;
5559
}
5660
return json {
5761
{"code", code},

tools/server/server-common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ enum error_type {
6262
ERROR_TYPE_UNAVAILABLE, // custom error
6363
ERROR_TYPE_NOT_SUPPORTED, // custom error
6464
ERROR_TYPE_EXCEED_CONTEXT_SIZE, // custom error
65+
ERROR_TYPE_INVALID_PROMPT, // custom error - for bad token IDs in prompt array
6566
};
6667

6768
// thin wrapper around common_grammar_trigger with (de)serialization functions

tools/server/server-context.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1709,7 +1709,7 @@ struct server_context_impl {
17091709
}
17101710

17111711
if (!task.tokens.validate(ctx_tgt)) {
1712-
send_error(task, "Prompt contains invalid tokens", ERROR_TYPE_INVALID_REQUEST);
1712+
send_error(task, "Prompt contains invalid tokens", ERROR_TYPE_INVALID_PROMPT);
17131713
return false;
17141714
}
17151715

@@ -2172,7 +2172,7 @@ struct server_context_impl {
21722172
task.cli_prompt.clear();
21732173
task.cli_files.clear();
21742174
} catch (const std::exception & e) {
2175-
send_error(task, std::string("Failed to format input: ") + e.what(), ERROR_TYPE_INVALID_REQUEST);
2175+
send_error(task, std::string("Failed to format input: ") + e.what(), ERROR_TYPE_INVALID_PROMPT);
21762176
return false;
21772177
}
21782178
return true;

0 commit comments

Comments
 (0)