Skip to content

Commit 73094ea

Browse files
authored
Merge pull request #4 from guardrails-ai/get-validator-metrics-summary
Get validator metrics
2 parents 5ab8c35 + 2f6603d commit 73094ea

File tree

2 files changed

+120
-3
lines changed

2 files changed

+120
-3
lines changed

service-specs/guardrails-service-spec.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,11 +307,15 @@ components:
307307
type: object
308308
properties:
309309
schema:
310-
type: object
311-
additionalProperties:
312-
$ref: "#/components/schemas/DataType"
310+
oneOf:
311+
- $ref: "#/components/schemas/JsonSchema"
312+
- $ref: "#/components/schemas/DataType"
313313
required:
314314
- schema
315+
JsonSchema:
316+
type: object
317+
additionalProperties:
318+
$ref: "#/components/schemas/DataType"
315319
DataType:
316320
type: object
317321
properties:

service-specs/reporting-service-spec.yml

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,62 @@ paths:
7979
application/json:
8080
schema:
8181
$ref: "#/components/schemas/HttpError"
82+
/validators/metrics:
83+
get:
84+
operationId: getValidatorMetrics
85+
summary: Returns an array of ValidatorMetrics for a given time range. If startTime or endTime are ommitted, a five minute duration is used by default. Default page size is 10, but this page size applied to guard steps not validator metrics. Have to think this one out a little more.
86+
parameters:
87+
- $ref: "#/components/parameters/StartTime"
88+
- $ref: "#/components/parameters/EndTime"
89+
- $ref: "#/components/parameters/PageNumber"
90+
tags:
91+
- Metrics
92+
security:
93+
- apiKeyAuth: []
94+
- bearerAuth: []
95+
responses:
96+
"200":
97+
description: Returns metrics for Guards
98+
content:
99+
application/json:
100+
schema:
101+
type: array
102+
items:
103+
$ref: "#/components/schemas/ValidatorMetrics"
104+
default:
105+
description: Unexpected error
106+
content:
107+
application/json:
108+
schema:
109+
$ref: "#/components/schemas/HttpError"
110+
/validators/{validatorName}/runs/{requestId}/instances/{validatorInstanceId}/metrics:
111+
get:
112+
operationId: getValidatorRunMetrics
113+
summary: Returns an arary of ValidatorRunMetrics for a given request.
114+
parameters:
115+
- $ref: "#/components/parameters/ValidatorName"
116+
- $ref: "#/components/parameters/RequestId"
117+
- $ref: "#/components/parameters/ValidatorInstanceId"
118+
tags:
119+
- Metrics
120+
security:
121+
- apiKeyAuth: []
122+
- bearerAuth: []
123+
responses:
124+
"200":
125+
description: Returns metrics for Guard request
126+
content:
127+
application/json:
128+
schema:
129+
type: array
130+
items:
131+
$ref: "#/components/schemas/ValidatorRunMetrics"
132+
default:
133+
description: Unexpected error
134+
content:
135+
application/json:
136+
schema:
137+
$ref: "#/components/schemas/HttpError"
82138
components:
83139
securitySchemes:
84140
bearerAuth:
@@ -206,8 +262,14 @@ components:
206262
ValidatorMetrics:
207263
type: object
208264
properties:
265+
instanceId:
266+
type: string
209267
name:
210268
type: string
269+
requestId:
270+
type: string
271+
guardName:
272+
type: string
211273
startTime:
212274
type: string
213275
format: date-time
@@ -226,13 +288,50 @@ components:
226288
type: number
227289
description: The number of tokens consumed if the validator calls an LLM. Only applies to validators that call LLMs.
228290
required:
291+
- instanceId
229292
- name
293+
- requestId
294+
- guardName
230295
- startTime
231296
- endTime
232297
- durationInMillis
233298
- input
234299
- output
235300
- status
301+
ValidatorRunMetrics:
302+
allOf:
303+
- $ref: '#/components/schemas/ValidatorMetrics'
304+
- $ref: '#/components/schemas/ValidatorRunMetricDetails'
305+
ValidatorRunMetricDetails:
306+
type: object
307+
properties:
308+
stepNumber:
309+
type: integer
310+
resultType:
311+
type: string
312+
failAction:
313+
$ref: '#/components/schemas/OnFailOptions'
314+
parameters:
315+
type: object
316+
properties: {}
317+
additionalProperties:
318+
type: string
319+
required:
320+
- stepNumber
321+
- resultType
322+
- failAction
323+
- parameters
324+
OnFailOptions:
325+
type: string
326+
enum: [
327+
"exception",
328+
"filter",
329+
"fix",
330+
"fix_reask",
331+
"noop",
332+
"reask",
333+
"refrain"
334+
]
236335
parameters:
237336
StartTime:
238337
name: startTime
@@ -270,5 +369,19 @@ components:
270369
in: path
271370
description: Request id aka trace id for a validate-{guard-name} span
272371
required: true
372+
schema:
373+
type: string
374+
ValidatorName:
375+
name: validatorName
376+
in: path
377+
description: the validator's registered name
378+
required: true
379+
schema:
380+
type: string
381+
ValidatorInstanceId:
382+
name: validatorInstanceId
383+
in: path
384+
description: the instanceId from ValidatorMetrics
385+
required: true
273386
schema:
274387
type: string

0 commit comments

Comments
 (0)