ML Detector API
Table of Contents
upsquad/ml/v1/detector.proto
ClassifyRequest
ClassifyRequest carries the text to score plus attribution metadata used only for metric labels and structured logs.
| Field | Type | Label | Description |
|---|---|---|---|
| text | string | text is the user message to classify. Caller MUST enforce a 32KB soft ceiling; the service rejects >64KB with INVALID_ARGUMENT and logs 32–64KB as oversized-but-truncated. | |
| tenant_id | string | tenant_id is the calling organization UUID. Used for metric labels only; the sidecar does not authorise per-tenant access. | |
| session_id | string | session_id is the agent session UUID. Used for log correlation. | |
| agent_id | string | agent_id is the invoking agent UUID. Used for metric labels. | |
| model_hint | string | model_hint selects the classifier model. Wave 5 accepts exactly "prompt-guard-86m"; any other value returns INVALID_ARGUMENT. |
ClassifyResponse
ClassifyResponse carries the classifier verdict plus raw scores so the orchestrator can emit shadow-phase metrics without re-thresholding.
| Field | Type | Label | Description |
|---|---|---|---|
| jailbreak_score | float | jailbreak_score is the Prompt-Guard JAILBREAK class probability, range [0.0, 1.0]. | |
| indirect_injection_score | float | indirect_injection_score is the Prompt-Guard INJECTION class probability, range [0.0, 1.0]. Reserved for Wave 5.1 tuning. | |
| verdict | string | verdict is one of "allow", "warn", "block" — computed server-side from the tenant-provided thresholds passed in ClassifyRequest. | |
| latency_ms | int32 | latency_ms is the sidecar-side wall-clock inference time in ms. | |
| model_version | string | model_version identifies the classifier build for audit rows, e.g. "prompt-guard-86m@v1". | |
| classified_at | google.protobuf.Timestamp | classified_at is when the sidecar finished inference. |
ModerateRequest
ModerateRequest is the LLD 23 placeholder. Wave 5 LLD 22 returns UNIMPLEMENTED from the server; shape may evolve in LLD 23 without a breaking change by extending reserved field numbers.
| Field | Type | Label | Description |
|---|---|---|---|
| text | string | text is the content to moderate. | |
| tenant_id | string | tenant_id is the calling organization UUID. | |
| session_id | string | session_id is the agent session UUID. | |
| agent_id | string | agent_id is the invoking agent UUID. |
ModerateResponse
ModerateResponse is the LLD 23 placeholder. Wave 5 LLD 22 returns UNIMPLEMENTED; LLD 23 defines the fields.
MLDetectorService
MLDetectorService hosts the Wave 5 ML inference RPCs. Runs in the
ml-detector sidecar Deployment (namespace: platform). All RPCs are
UNARY. The Go bridge in internal/runtime/security/mlclassifier calls
Classify; LLD 23 fills the Moderate stub.
| Method Name | Request Type | Response Type | Description |
|---|---|---|---|
| Classify | ClassifyRequest | ClassifyResponse | Classify scores a single user message for prompt-injection / jailbreak risk using Prompt-Guard-86M. Latency budget: P95 <75ms including one RTT from the orchestrator. The service must fail fast on any input larger than 64KB with INVALID_ARGUMENT. |
| Moderate | ModerateRequest | ModerateResponse | Moderate scores a text buffer for policy-category violations. LLD 22 returns UNIMPLEMENTED; LLD 23 fills the body. Request and response shapes are minimal here to let LLD 23 land without a second proto. |
Scalar Value Types
| .proto Type | Notes | C++ | Java | Python | Go | C# | PHP | Ruby |
|---|---|---|---|---|---|---|---|---|
| double | double | double | float | float64 | double | float | Float | |
| float | float | float | float | float32 | float | float | Float | |
| int32 | Uses variable-length encoding. Inefficient for encoding negative numbers – if your field is likely to have negative values, use sint32 instead. | int32 | int | int | int32 | int | integer | Bignum or Fixnum (as required) |
| int64 | Uses variable-length encoding. Inefficient for encoding negative numbers – if your field is likely to have negative values, use sint64 instead. | int64 | long | int/long | int64 | long | integer/string | Bignum |
| uint32 | Uses variable-length encoding. | uint32 | int | int/long | uint32 | uint | integer | Bignum or Fixnum (as required) |
| uint64 | Uses variable-length encoding. | uint64 | long | int/long | uint64 | ulong | integer/string | Bignum or Fixnum (as required) |
| sint32 | Uses variable-length encoding. Signed int value. These more efficiently encode negative numbers than regular int32s. | int32 | int | int | int32 | int | integer | Bignum or Fixnum (as required) |
| sint64 | Uses variable-length encoding. Signed int value. These more efficiently encode negative numbers than regular int64s. | int64 | long | int/long | int64 | long | integer/string | Bignum |
| fixed32 | Always four bytes. More efficient than uint32 if values are often greater than 2^28. | uint32 | int | int | uint32 | uint | integer | Bignum or Fixnum (as required) |
| fixed64 | Always eight bytes. More efficient than uint64 if values are often greater than 2^56. | uint64 | long | int/long | uint64 | ulong | integer/string | Bignum |
| sfixed32 | Always four bytes. | int32 | int | int | int32 | int | integer | Bignum or Fixnum (as required) |
| sfixed64 | Always eight bytes. | int64 | long | int/long | int64 | long | integer/string | Bignum |
| bool | bool | boolean | boolean | bool | bool | boolean | TrueClass/FalseClass | |
| string | A string must always contain UTF-8 encoded or 7-bit ASCII text. | string | String | str/unicode | string | string | string | String (UTF-8) |
| bytes | May contain any arbitrary sequence of bytes. | string | ByteString | str | []byte | ByteString | string | String (ASCII-8BIT) |