deeprails

package module
v0.25.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 27, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

README

DeepRails Go API Library

Go Reference

The DeepRails Go library provides convenient access to the DeepRails REST API from applications written in Go.

Installation

import (
	"github.com/deeprails/deeprails-go-sdk" // imported as deeprails
)

Or to pin the version:

go get -u 'github.com/deeprails/deeprails-go-sdk@v0.25.0'

Requirements

This library requires Go 1.22+.

Usage

The full API of this library can be found in api.md.

package main

import (
	"context"
	"fmt"

	"github.com/deeprails/deeprails-go-sdk"
	"github.com/deeprails/deeprails-go-sdk/option"
)

func main() {
	client := deeprails.NewClient(
		option.WithAPIKey("My API Key"), // defaults to os.LookupEnv("DEEPRAILS_API_KEY")
	)
	defendCreateResponse, err := client.Defend.NewWorkflow(context.TODO(), deeprails.DefendNewWorkflowParams{
		ImprovementAction: deeprails.F(deeprails.DefendNewWorkflowParamsImprovementActionFixit),
		Name:              deeprails.F("Push Alert Workflow"),
		ThresholdType:     deeprails.F(deeprails.DefendNewWorkflowParamsThresholdTypeCustom),
		CustomHallucinationThresholdValues: deeprails.F(map[string]float64{
			"completeness":          0.700000,
			"instruction_adherence": 0.750000,
		}),
		WebSearch: deeprails.F(true),
	})
	if err != nil {
		panic(err.Error())
	}
	fmt.Printf("%+v\n", defendCreateResponse.WorkflowID)
}

Request fields

All request parameters are wrapped in a generic Field type, which we use to distinguish zero values from null or omitted fields.

This prevents accidentally sending a zero value if you forget a required parameter, and enables explicitly sending null, false, '', or 0 on optional parameters. Any field not specified is not sent.

To construct fields with values, use the helpers String(), Int(), Float(), or most commonly, the generic F[T](). To send a null, use Null[T](), and to send a nonconforming value, use Raw[T](any). For example:

params := FooParams{
	Name: deeprails.F("hello"),

	// Explicitly send `"description": null`
	Description: deeprails.Null[string](),

	Point: deeprails.F(deeprails.Point{
		X: deeprails.Int(0),
		Y: deeprails.Int(1),

		// In cases where the API specifies a given type,
		// but you want to send something else, use `Raw`:
		Z: deeprails.Raw[int64](0.01), // sends a float
	}),
}
Response objects

All fields in response structs are value types (not pointers or wrappers).

If a given field is null, not present, or invalid, the corresponding field will simply be its zero value.

All response structs also include a special JSON field, containing more detailed information about each property, which you can use like so:

if res.Name == "" {
	// true if `"name"` is either not present or explicitly null
	res.JSON.Name.IsNull()

	// true if the `"name"` key was not present in the response JSON at all
	res.JSON.Name.IsMissing()

	// When the API returns data that cannot be coerced to the expected type:
	if res.JSON.Name.IsInvalid() {
		raw := res.JSON.Name.Raw()

		legacyName := struct{
			First string `json:"first"`
			Last  string `json:"last"`
		}{}
		json.Unmarshal([]byte(raw), &legacyName)
		name = legacyName.First + " " + legacyName.Last
	}
}

These .JSON structs also include an Extras map containing any properties in the json response that were not specified in the struct. This can be useful for API features not yet present in the SDK.

body := res.JSON.ExtraFields["my_unexpected_field"].Raw()
RequestOptions

This library uses the functional options pattern. Functions defined in the option package return a RequestOption, which is a closure that mutates a RequestConfig. These options can be supplied to the client or at individual requests. For example:

client := deeprails.NewClient(
	// Adds a header to every request made by the client
	option.WithHeader("X-Some-Header", "custom_header_info"),
)

client.Defend.NewWorkflow(context.TODO(), ...,
	// Override the header
	option.WithHeader("X-Some-Header", "some_other_custom_header_info"),
	// Add an undocumented field to the request body, using sjson syntax
	option.WithJSONSet("some.json.path", map[string]string{"my": "object"}),
)

See the full list of request options.

Pagination

This library provides some conveniences for working with paginated list endpoints.

You can use .ListAutoPaging() methods to iterate through items across all pages:

Or you can use simple .List() methods to fetch a single page and receive a standard response object with additional helper methods like .GetNextPage(), e.g.:

Errors

When the API returns a non-success status code, we return an error with type *deeprails.Error. This contains the StatusCode, *http.Request, and *http.Response values of the request, as well as the JSON of the error body (much like other response objects in the SDK).

To handle errors, we recommend that you use the errors.As pattern:

_, err := client.Defend.NewWorkflow(context.TODO(), deeprails.DefendNewWorkflowParams{
	ImprovementAction: deeprails.F(deeprails.DefendNewWorkflowParamsImprovementActionFixit),
	Name:              deeprails.F("Push Alert Workflow"),
	ThresholdType:     deeprails.F(deeprails.DefendNewWorkflowParamsThresholdTypeCustom),
	CustomHallucinationThresholdValues: deeprails.F(map[string]float64{
		"completeness":          0.700000,
		"instruction_adherence": 0.750000,
	}),
	WebSearch: deeprails.F(true),
})
if err != nil {
	var apierr *deeprails.Error
	if errors.As(err, &apierr) {
		println(string(apierr.DumpRequest(true)))  // Prints the serialized HTTP request
		println(string(apierr.DumpResponse(true))) // Prints the serialized HTTP response
	}
	panic(err.Error()) // GET "/defend": 400 Bad Request { ... }
}

When other errors occur, they are returned unwrapped; for example, if HTTP transport fails, you might receive *url.Error wrapping *net.OpError.

Timeouts

Requests do not time out by default; use context to configure a timeout for a request lifecycle.

Note that if a request is retried, the context timeout does not start over. To set a per-retry timeout, use option.WithRequestTimeout().

// This sets the timeout for the request, including all the retries.
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()
client.Defend.NewWorkflow(
	ctx,
	deeprails.DefendNewWorkflowParams{
		ImprovementAction: deeprails.F(deeprails.DefendNewWorkflowParamsImprovementActionFixit),
		Name:              deeprails.F("Push Alert Workflow"),
		ThresholdType:     deeprails.F(deeprails.DefendNewWorkflowParamsThresholdTypeCustom),
		CustomHallucinationThresholdValues: deeprails.F(map[string]float64{
			"completeness":          0.700000,
			"instruction_adherence": 0.750000,
		}),
		WebSearch: deeprails.F(true),
	},
	// This sets the per-retry timeout
	option.WithRequestTimeout(20*time.Second),
)
File uploads

Request parameters that correspond to file uploads in multipart requests are typed as param.Field[io.Reader]. The contents of the io.Reader will by default be sent as a multipart form part with the file name of "anonymous_file" and content-type of "application/octet-stream".

The file name and content-type can be customized by implementing Name() string or ContentType() string on the run-time type of io.Reader. Note that os.File implements Name() string, so a file returned by os.Open will be sent with the file name on disk.

We also provide a helper deeprails.FileParam(reader io.Reader, filename string, contentType string) which can be used to wrap any io.Reader with the appropriate file name and content type.

Retries

Certain errors will be automatically retried 2 times by default, with a short exponential backoff. We retry by default all connection errors, 408 Request Timeout, 409 Conflict, 429 Rate Limit, and >=500 Internal errors.

You can use the WithMaxRetries option to configure or disable this:

// Configure the default for all requests:
client := deeprails.NewClient(
	option.WithMaxRetries(0), // default is 2
)

// Override per-request:
client.Defend.NewWorkflow(
	context.TODO(),
	deeprails.DefendNewWorkflowParams{
		ImprovementAction: deeprails.F(deeprails.DefendNewWorkflowParamsImprovementActionFixit),
		Name:              deeprails.F("Push Alert Workflow"),
		ThresholdType:     deeprails.F(deeprails.DefendNewWorkflowParamsThresholdTypeCustom),
		CustomHallucinationThresholdValues: deeprails.F(map[string]float64{
			"completeness":          0.700000,
			"instruction_adherence": 0.750000,
		}),
		WebSearch: deeprails.F(true),
	},
	option.WithMaxRetries(5),
)
Accessing raw response data (e.g. response headers)

You can access the raw HTTP response data by using the option.WithResponseInto() request option. This is useful when you need to examine response headers, status codes, or other details.

// Create a variable to store the HTTP response
var response *http.Response
defendCreateResponse, err := client.Defend.NewWorkflow(
	context.TODO(),
	deeprails.DefendNewWorkflowParams{
		ImprovementAction: deeprails.F(deeprails.DefendNewWorkflowParamsImprovementActionFixit),
		Name:              deeprails.F("Push Alert Workflow"),
		ThresholdType:     deeprails.F(deeprails.DefendNewWorkflowParamsThresholdTypeCustom),
		CustomHallucinationThresholdValues: deeprails.F(map[string]float64{
			"completeness":          0.700000,
			"instruction_adherence": 0.750000,
		}),
		WebSearch: deeprails.F(true),
	},
	option.WithResponseInto(&response),
)
if err != nil {
	// handle error
}
fmt.Printf("%+v\n", defendCreateResponse)

fmt.Printf("Status Code: %d\n", response.StatusCode)
fmt.Printf("Headers: %+#v\n", response.Header)
Making custom/undocumented requests

This library is typed for convenient access to the documented API. If you need to access undocumented endpoints, params, or response properties, the library can still be used.

Undocumented endpoints

To make requests to undocumented endpoints, you can use client.Get, client.Post, and other HTTP verbs. RequestOptions on the client, such as retries, will be respected when making these requests.

var (
    // params can be an io.Reader, a []byte, an encoding/json serializable object,
    // or a "…Params" struct defined in this library.
    params map[string]interface{}

    // result can be an []byte, *http.Response, a encoding/json deserializable object,
    // or a model defined in this library.
    result *http.Response
)
err := client.Post(context.Background(), "/unspecified", params, &result)
if err != nil {
    …
}
Undocumented request params

To make requests using undocumented parameters, you may use either the option.WithQuerySet() or the option.WithJSONSet() methods.

params := FooNewParams{
    ID:   deeprails.F("id_xxxx"),
    Data: deeprails.F(FooNewParamsData{
        FirstName: deeprails.F("John"),
    }),
}
client.Foo.New(context.Background(), params, option.WithJSONSet("data.last_name", "Doe"))
Undocumented response properties

To access undocumented response properties, you may either access the raw JSON of the response as a string with result.JSON.RawJSON(), or get the raw JSON of a particular field on the result with result.JSON.Foo.Raw().

Any fields that are not present on the response struct will be saved and can be accessed by result.JSON.ExtraFields() which returns the extra fields as a map[string]Field.

Middleware

We provide option.WithMiddleware which applies the given middleware to requests.

func Logger(req *http.Request, next option.MiddlewareNext) (res *http.Response, err error) {
	// Before the request
	start := time.Now()
	LogReq(req)

	// Forward the request to the next handler
	res, err = next(req)

	// Handle stuff after the request
	end := time.Now()
	LogRes(res, err, start - end)

    return res, err
}

client := deeprails.NewClient(
	option.WithMiddleware(Logger),
)

When multiple middlewares are provided as variadic arguments, the middlewares are applied left to right. If option.WithMiddleware is given multiple times, for example first in the client then the method, the middleware in the client will run first and the middleware given in the method will run next.

You may also replace the default http.Client with option.WithHTTPClient(client). Only one http client is accepted (this overwrites any previous client) and receives requests after any middleware has been applied.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool

func Bool(value bool) param.Field[bool]

Bool is a param field helper which helps specify bools.

func DefaultClientOptions

func DefaultClientOptions() []option.RequestOption

DefaultClientOptions read from the environment (DEEPRAILS_API_KEY, DEEP_RAILS_BASE_URL). This should be used to initialize new clients.

func F added in v0.2.0

func F[T any](value T) param.Field[T]

F is a param field helper used to initialize a param.Field generic struct. This helps specify null, zero values, and overrides, as well as normal values. You can read more about this in our README.

func FileParam added in v0.2.0

func FileParam(reader io.Reader, filename string, contentType string) param.Field[io.Reader]

FileParam is a param field helper which helps files with a mime content-type.

func Float

func Float(value float64) param.Field[float64]

Float is a param field helper which helps specify floats.

func Int

func Int(value int64) param.Field[int64]

Int is a param field helper which helps specify integers. This is particularly helpful when specifying integer constants for fields.

func Null added in v0.2.0

func Null[T any]() param.Field[T]

Null is a param field helper which explicitly sends null to the API.

func Raw added in v0.2.0

func Raw[T any](value any) param.Field[T]

Raw is a param field helper for specifying values for fields when the type you are looking to send is different from the type that is specified in the SDK. For example, if the type of the field is an integer, but you want to send a float, you could do that by setting the corresponding field with Raw[int](0.5).

func String

func String(value string) param.Field[string]

String is a param field helper which helps specify strings.

Types

type Client

type Client struct {
	Options []option.RequestOption
	Defend  *DefendService
	Monitor *MonitorService
	Files   *FileService
}

Client creates a struct with services and top level methods that help with interacting with the deep rails API. You should not instantiate this client directly, and instead use the NewClient method instead.

func NewClient

func NewClient(opts ...option.RequestOption) (r *Client)

NewClient generates a new client with the default option read from the environment (DEEPRAILS_API_KEY, DEEP_RAILS_BASE_URL). The option passed in as arguments are applied after these default arguments, and all option will be passed down to the services and requests that this client makes.

func (*Client) Delete

func (r *Client) Delete(ctx context.Context, path string, params interface{}, res interface{}, opts ...option.RequestOption) error

Delete makes a DELETE request with the given URL, params, and optionally deserializes to a response. See [Execute] documentation on the params and response.

func (*Client) Execute

func (r *Client) Execute(ctx context.Context, method string, path string, params interface{}, res interface{}, opts ...option.RequestOption) error

Execute makes a request with the given context, method, URL, request params, response, and request options. This is useful for hitting undocumented endpoints while retaining the base URL, auth, retries, and other options from the client.

If a byte slice or an io.Reader is supplied to params, it will be used as-is for the request body.

The params is by default serialized into the body using encoding/json. If your type implements a MarshalJSON function, it will be used instead to serialize the request. If a URLQuery method is implemented, the returned url.Values will be used as query strings to the url.

If your params struct uses param.Field, you must provide either [MarshalJSON], [URLQuery], and/or [MarshalForm] functions. It is undefined behavior to use a struct uses param.Field without specifying how it is serialized.

Any "…Params" object defined in this library can be used as the request argument. Note that 'path' arguments will not be forwarded into the url.

The response body will be deserialized into the res variable, depending on its type:

  • A pointer to a *http.Response is populated by the raw response.
  • A pointer to a byte array will be populated with the contents of the request body.
  • A pointer to any other type uses this library's default JSON decoding, which respects UnmarshalJSON if it is defined on the type.
  • A nil value will not read the response body.

For even greater flexibility, see option.WithResponseInto and option.WithResponseBodyInto.

func (*Client) Get

func (r *Client) Get(ctx context.Context, path string, params interface{}, res interface{}, opts ...option.RequestOption) error

Get makes a GET request with the given URL, params, and optionally deserializes to a response. See [Execute] documentation on the params and response.

func (*Client) Patch

func (r *Client) Patch(ctx context.Context, path string, params interface{}, res interface{}, opts ...option.RequestOption) error

Patch makes a PATCH request with the given URL, params, and optionally deserializes to a response. See [Execute] documentation on the params and response.

func (*Client) Post

func (r *Client) Post(ctx context.Context, path string, params interface{}, res interface{}, opts ...option.RequestOption) error

Post makes a POST request with the given URL, params, and optionally deserializes to a response. See [Execute] documentation on the params and response.

func (*Client) Put

func (r *Client) Put(ctx context.Context, path string, params interface{}, res interface{}, opts ...option.RequestOption) error

Put makes a PUT request with the given URL, params, and optionally deserializes to a response. See [Execute] documentation on the params and response.

type DefendCreateResponse added in v0.12.0

type DefendCreateResponse struct {
	// The time the workflow was created in UTC.
	CreatedAt time.Time `json:"created_at" api:"required" format:"date-time"`
	// Status of the selected workflow. May be `inactive` or `active`. Inactive
	// workflows will not accept events.
	Status DefendCreateResponseStatus `json:"status" api:"required"`
	// A unique workflow ID.
	WorkflowID string                   `json:"workflow_id" api:"required"`
	JSON       defendCreateResponseJSON `json:"-"`
}

func (*DefendCreateResponse) UnmarshalJSON added in v0.12.0

func (r *DefendCreateResponse) UnmarshalJSON(data []byte) (err error)

type DefendCreateResponseStatus added in v0.12.0

type DefendCreateResponseStatus string

Status of the selected workflow. May be `inactive` or `active`. Inactive workflows will not accept events.

const (
	DefendCreateResponseStatusInactive DefendCreateResponseStatus = "inactive"
	DefendCreateResponseStatusActive   DefendCreateResponseStatus = "active"
)

func (DefendCreateResponseStatus) IsKnown added in v0.12.0

func (r DefendCreateResponseStatus) IsKnown() bool

type DefendGetWorkflowParams added in v0.12.0

type DefendGetWorkflowParams struct {
	// Limit the number of returned events associated with this workflow. Defaults
	// to 10.
	Limit param.Field[int64] `query:"limit"`
}

func (DefendGetWorkflowParams) URLQuery added in v0.12.0

func (r DefendGetWorkflowParams) URLQuery() (v url.Values)

URLQuery serializes DefendGetWorkflowParams's query parameters as `url.Values`.

type DefendNewWorkflowParams

type DefendNewWorkflowParams struct {
	// The action used to improve outputs that fail one or more guardrail metrics for
	// the workflow events. May be `regen`, `fixit`, or `do_nothing`. ReGen runs the
	// user's input prompt with minor induced variance. FixIt attempts to directly
	// address the shortcomings of the output using the guardrail failure rationale. Do
	// Nothing does not attempt any improvement.
	ImprovementAction param.Field[DefendNewWorkflowParamsImprovementAction] `json:"improvement_action" api:"required"`
	// Name of the workflow.
	Name param.Field[string] `json:"name" api:"required"`
	// Type of thresholds to use for the workflow, either `automatic` or `custom`.
	// Automatic thresholds are assigned internally after the user specifies a
	// qualitative tolerance for the metrics, whereas custom metrics allow the user to
	// set the threshold for each metric as a floating point number between 0.0 and
	// 1.0.
	ThresholdType param.Field[DefendNewWorkflowParamsThresholdType] `json:"threshold_type" api:"required"`
	// Mapping of guardrail metrics to hallucination tolerance levels (either `low`,
	// `medium`, or `high`). Possible metrics are `completeness`,
	// `instruction_adherence`, `context_adherence`, `ground_truth_adherence`, or
	// `comprehensive_safety`.
	AutomaticHallucinationToleranceLevels param.Field[map[string]DefendNewWorkflowParamsAutomaticHallucinationToleranceLevels] `json:"automatic_hallucination_tolerance_levels"`
	// Context includes any structured information that directly relates to the model’s
	// input and expected output—e.g., the recent turn-by-turn history between an AI
	// tutor and a student, facts or state passed through an agentic workflow, or other
	// domain-specific signals your system already knows and wants the model to
	// condition on. This field determines whether to enable context awareness for this
	// workflow's evaluations. Defaults to false.
	ContextAwareness param.Field[bool] `json:"context_awareness"`
	// Mapping of guardrail metrics to floating point threshold values. Possible
	// metrics are `correctness`, `completeness`, `instruction_adherence`,
	// `context_adherence`, `ground_truth_adherence`, or `comprehensive_safety`.
	CustomHallucinationThresholdValues param.Field[map[string]float64] `json:"custom_hallucination_threshold_values"`
	// Description for the workflow.
	Description param.Field[string] `json:"description"`
	// An array of file IDs to search in the workflow's evaluations. Files must be
	// uploaded via the DeepRails API first.
	FileSearch param.Field[[]string] `json:"file_search"`
	// Max. number of improvement action attempts until a given event passes the
	// guardrails. Defaults to 10.
	MaxImprovementAttempts param.Field[int64] `json:"max_improvement_attempts"`
	// Whether to enable web search for this workflow's evaluations. Defaults to false.
	WebSearch param.Field[bool] `json:"web_search"`
}

func (DefendNewWorkflowParams) MarshalJSON

func (r DefendNewWorkflowParams) MarshalJSON() (data []byte, err error)

type DefendNewWorkflowParamsAutomaticHallucinationToleranceLevels added in v0.6.0

type DefendNewWorkflowParamsAutomaticHallucinationToleranceLevels string
const (
	DefendNewWorkflowParamsAutomaticHallucinationToleranceLevelsLow    DefendNewWorkflowParamsAutomaticHallucinationToleranceLevels = "low"
	DefendNewWorkflowParamsAutomaticHallucinationToleranceLevelsMedium DefendNewWorkflowParamsAutomaticHallucinationToleranceLevels = "medium"
	DefendNewWorkflowParamsAutomaticHallucinationToleranceLevelsHigh   DefendNewWorkflowParamsAutomaticHallucinationToleranceLevels = "high"
)

func (DefendNewWorkflowParamsAutomaticHallucinationToleranceLevels) IsKnown added in v0.6.0

type DefendNewWorkflowParamsImprovementAction

type DefendNewWorkflowParamsImprovementAction string

The action used to improve outputs that fail one or more guardrail metrics for the workflow events. May be `regen`, `fixit`, or `do_nothing`. ReGen runs the user's input prompt with minor induced variance. FixIt attempts to directly address the shortcomings of the output using the guardrail failure rationale. Do Nothing does not attempt any improvement.

const (
	DefendNewWorkflowParamsImprovementActionRegen     DefendNewWorkflowParamsImprovementAction = "regen"
	DefendNewWorkflowParamsImprovementActionFixit     DefendNewWorkflowParamsImprovementAction = "fixit"
	DefendNewWorkflowParamsImprovementActionDoNothing DefendNewWorkflowParamsImprovementAction = "do_nothing"
)

func (DefendNewWorkflowParamsImprovementAction) IsKnown added in v0.2.0

type DefendNewWorkflowParamsThresholdType added in v0.12.0

type DefendNewWorkflowParamsThresholdType string

Type of thresholds to use for the workflow, either `automatic` or `custom`. Automatic thresholds are assigned internally after the user specifies a qualitative tolerance for the metrics, whereas custom metrics allow the user to set the threshold for each metric as a floating point number between 0.0 and 1.0.

const (
	DefendNewWorkflowParamsThresholdTypeAutomatic DefendNewWorkflowParamsThresholdType = "automatic"
	DefendNewWorkflowParamsThresholdTypeCustom    DefendNewWorkflowParamsThresholdType = "custom"
)

func (DefendNewWorkflowParamsThresholdType) IsKnown added in v0.12.0

type DefendResponse

type DefendResponse struct {
	// Mapping of guardrail metric names to tolerance values. Values can be strings
	// (`low`, `medium`, `high`) for automatic tolerance levels.
	AutomaticHallucinationToleranceLevels map[string]DefendResponseAutomaticHallucinationToleranceLevel `json:"automatic_hallucination_tolerance_levels" api:"required"`
	// Extended AI capabilities available to the event, if any. Can be `web_search`,
	// `file_search`, and/or `context_awareness`.
	Capabilities []DefendResponseCapability `json:"capabilities" api:"required"`
	// The time the workflow was created in UTC.
	CreatedAt time.Time `json:"created_at" api:"required" format:"date-time"`
	// Mapping of guardrail metric names to threshold values. Values can be floating
	// point numbers (0.0-1.0) for custom thresholds.
	CustomHallucinationThresholdValues map[string]float64 `json:"custom_hallucination_threshold_values" api:"required"`
	// A description for the workflow, to help you remember what that workflow means to
	// your organization.
	Description string `json:"description" api:"required"`
	// An array of events associated with this workflow.
	Events []DefendResponseEvent `json:"events" api:"required"`
	// List of files associated with the workflow. If this is not empty, models can
	// search these files when performing evaluations or remediations
	Files []DefendResponseFile `json:"files" api:"required"`
	// A human-readable name for the workflow that will correspond to it's workflow ID.
	Name string `json:"name" api:"required"`
	// Status of the selected workflow. May be `inactive` or `active`. Inactive
	// workflows will not accept events.
	Status DefendResponseStatus `json:"status" api:"required"`
	// Type of thresholds used to evaluate the event.
	ThresholdType DefendResponseThresholdType `json:"threshold_type" api:"required"`
	// The most recent time the workflow was updated in UTC.
	UpdatedAt time.Time `json:"updated_at" api:"required" format:"date-time"`
	// A unique workflow ID used to identify the workflow in other endpoints.
	WorkflowID string `json:"workflow_id" api:"required"`
	// The action used to improve outputs that fail one or more guardrail metrics for
	// the workflow events.
	ImprovementAction DefendResponseImprovementAction `json:"improvement_action"`
	Stats             DefendResponseStats             `json:"stats"`
	JSON              defendResponseJSON              `json:"-"`
}

func (*DefendResponse) UnmarshalJSON

func (r *DefendResponse) UnmarshalJSON(data []byte) (err error)

type DefendResponseAutomaticHallucinationToleranceLevel added in v0.12.0

type DefendResponseAutomaticHallucinationToleranceLevel string
const (
	DefendResponseAutomaticHallucinationToleranceLevelLow    DefendResponseAutomaticHallucinationToleranceLevel = "low"
	DefendResponseAutomaticHallucinationToleranceLevelMedium DefendResponseAutomaticHallucinationToleranceLevel = "medium"
	DefendResponseAutomaticHallucinationToleranceLevelHigh   DefendResponseAutomaticHallucinationToleranceLevel = "high"
)

func (DefendResponseAutomaticHallucinationToleranceLevel) IsKnown added in v0.12.0

type DefendResponseCapability added in v0.12.0

type DefendResponseCapability struct {
	Capability string                       `json:"capability"`
	JSON       defendResponseCapabilityJSON `json:"-"`
}

func (*DefendResponseCapability) UnmarshalJSON added in v0.12.0

func (r *DefendResponseCapability) UnmarshalJSON(data []byte) (err error)

type DefendResponseEvent added in v0.12.0

type DefendResponseEvent struct {
	// The ID of the billing request for the event.
	BillingRequestID string `json:"billing_request_id"`
	// An array of evaluations for this event.
	Evaluations []DefendResponseEventsEvaluation `json:"evaluations"`
	// A unique workflow event ID.
	EventID string `json:"event_id"`
	// Improved model output after improvement tool was applied.
	ImprovedModelOutput string `json:"improved_model_output"`
	// Status of the improvement tool used to improve the event. `improvement_required`
	// indicates that the evaluation is complete and the improvement action is needed
	// but is not taking place. `improved` and `improvement_failed` indicate when the
	// improvement action concludes, successfully and unsuccessfully, respectively.
	// `no_improvement_required` means that the first evaluation passed all its
	// metrics!
	ImprovementToolStatus DefendResponseEventsImprovementToolStatus `json:"improvement_tool_status"`
	// Status of the event.
	Status DefendResponseEventsStatus `json:"status"`
	JSON   defendResponseEventJSON    `json:"-"`
}

func (*DefendResponseEvent) UnmarshalJSON added in v0.12.0

func (r *DefendResponseEvent) UnmarshalJSON(data []byte) (err error)

type DefendResponseEventsEvaluation added in v0.12.0

type DefendResponseEventsEvaluation struct {
	// Analysis of the failures of the model_output according to the guardrail metrics
	// evaluated.
	AnalysisOfFailures string `json:"analysis_of_failures"`
	// The attempt number or identifier for this evaluation.
	Attempt string `json:"attempt"`
	// The time the evaluation was created in UTC.
	CreatedAt time.Time `json:"created_at" format:"date-time"`
	// Error message if the evaluation failed.
	ErrorMessage string `json:"error_message"`
	// The result of the evaluation.
	EvaluationResult map[string]interface{} `json:"evaluation_result"`
	// Status of the evaluation.
	EvaluationStatus string `json:"evaluation_status"`
	// Total cost of the evaluation.
	EvaluationTotalCost float64 `json:"evaluation_total_cost"`
	// An array of guardrail metrics evaluated.
	GuardrailMetrics []string `json:"guardrail_metrics"`
	// Status of the improvement tool used to improve the event. `improvement_required`
	// indicates that the evaluation is complete and the improvement action is needed
	// but is not taking place. `improved` and `improvement_failed` indicate when the
	// improvement action concludes, successfully and unsuccessfully, respectively.
	// `no_improvement_required` means that the first evaluation passed all its
	// metrics!
	ImprovementToolStatus DefendResponseEventsEvaluationsImprovementToolStatus `json:"improvement_tool_status"`
	// A list of key improvements made to the model_output to address the failures.
	KeyImprovements []string `json:"key_improvements"`
	// The model input used for the evaluation.
	ModelInput map[string]interface{} `json:"model_input"`
	// The model output that was evaluated.
	ModelOutput string `json:"model_output"`
	// The time the evaluation was last modified in UTC.
	ModifiedAt time.Time `json:"modified_at" format:"date-time"`
	// An optional tag for the evaluation.
	Nametag string `json:"nametag"`
	// Evaluation progress (0-100).
	Progress int64 `json:"progress"`
	// Run mode used for the evaluation.
	RunMode string                             `json:"run_mode"`
	JSON    defendResponseEventsEvaluationJSON `json:"-"`
}

func (*DefendResponseEventsEvaluation) UnmarshalJSON added in v0.12.0

func (r *DefendResponseEventsEvaluation) UnmarshalJSON(data []byte) (err error)

type DefendResponseEventsEvaluationsImprovementToolStatus added in v0.22.0

type DefendResponseEventsEvaluationsImprovementToolStatus string

Status of the improvement tool used to improve the event. `improvement_required` indicates that the evaluation is complete and the improvement action is needed but is not taking place. `improved` and `improvement_failed` indicate when the improvement action concludes, successfully and unsuccessfully, respectively. `no_improvement_required` means that the first evaluation passed all its metrics!

const (
	DefendResponseEventsEvaluationsImprovementToolStatusImproved              DefendResponseEventsEvaluationsImprovementToolStatus = "improved"
	DefendResponseEventsEvaluationsImprovementToolStatusImprovementFailed     DefendResponseEventsEvaluationsImprovementToolStatus = "improvement_failed"
	DefendResponseEventsEvaluationsImprovementToolStatusNoImprovementRequired DefendResponseEventsEvaluationsImprovementToolStatus = "no_improvement_required"
	DefendResponseEventsEvaluationsImprovementToolStatusImprovementRequired   DefendResponseEventsEvaluationsImprovementToolStatus = "improvement_required"
)

func (DefendResponseEventsEvaluationsImprovementToolStatus) IsKnown added in v0.22.0

type DefendResponseEventsImprovementToolStatus added in v0.21.0

type DefendResponseEventsImprovementToolStatus string

Status of the improvement tool used to improve the event. `improvement_required` indicates that the evaluation is complete and the improvement action is needed but is not taking place. `improved` and `improvement_failed` indicate when the improvement action concludes, successfully and unsuccessfully, respectively. `no_improvement_required` means that the first evaluation passed all its metrics!

const (
	DefendResponseEventsImprovementToolStatusImproved              DefendResponseEventsImprovementToolStatus = "improved"
	DefendResponseEventsImprovementToolStatusImprovementFailed     DefendResponseEventsImprovementToolStatus = "improvement_failed"
	DefendResponseEventsImprovementToolStatusNoImprovementRequired DefendResponseEventsImprovementToolStatus = "no_improvement_required"
	DefendResponseEventsImprovementToolStatusImprovementRequired   DefendResponseEventsImprovementToolStatus = "improvement_required"
)

func (DefendResponseEventsImprovementToolStatus) IsKnown added in v0.21.0

type DefendResponseEventsStatus added in v0.22.0

type DefendResponseEventsStatus string

Status of the event.

const (
	DefendResponseEventsStatusCompleted  DefendResponseEventsStatus = "completed"
	DefendResponseEventsStatusFailed     DefendResponseEventsStatus = "failed"
	DefendResponseEventsStatusInProgress DefendResponseEventsStatus = "in_progress"
)

func (DefendResponseEventsStatus) IsKnown added in v0.22.0

func (r DefendResponseEventsStatus) IsKnown() bool

type DefendResponseFile added in v0.12.0

type DefendResponseFile struct {
	FileID                string                 `json:"file_id"`
	FileName              string                 `json:"file_name"`
	FileSize              int64                  `json:"file_size"`
	PresignedURL          string                 `json:"presigned_url"`
	PresignedURLExpiresAt time.Time              `json:"presigned_url_expires_at" format:"date-time"`
	JSON                  defendResponseFileJSON `json:"-"`
}

func (*DefendResponseFile) UnmarshalJSON added in v0.12.0

func (r *DefendResponseFile) UnmarshalJSON(data []byte) (err error)

type DefendResponseImprovementAction

type DefendResponseImprovementAction string

The action used to improve outputs that fail one or more guardrail metrics for the workflow events.

const (
	DefendResponseImprovementActionRegen     DefendResponseImprovementAction = "regen"
	DefendResponseImprovementActionFixit     DefendResponseImprovementAction = "fixit"
	DefendResponseImprovementActionDoNothing DefendResponseImprovementAction = "do_nothing"
)

func (DefendResponseImprovementAction) IsKnown added in v0.2.0

type DefendResponseStats added in v0.12.0

type DefendResponseStats struct {
	// Number of AI outputs that failed the guardrails.
	OutputsBelowThreshold int64 `json:"outputs_below_threshold"`
	// Number of AI outputs that were improved.
	OutputsImproved int64 `json:"outputs_improved"`
	// Total number of AI outputs processed by the workflow.
	OutputsProcessed int64                   `json:"outputs_processed"`
	JSON             defendResponseStatsJSON `json:"-"`
}

func (*DefendResponseStats) UnmarshalJSON added in v0.12.0

func (r *DefendResponseStats) UnmarshalJSON(data []byte) (err error)

type DefendResponseStatus

type DefendResponseStatus string

Status of the selected workflow. May be `inactive` or `active`. Inactive workflows will not accept events.

const (
	DefendResponseStatusInactive DefendResponseStatus = "inactive"
	DefendResponseStatusActive   DefendResponseStatus = "active"
)

func (DefendResponseStatus) IsKnown added in v0.2.0

func (r DefendResponseStatus) IsKnown() bool

type DefendResponseThresholdType added in v0.12.0

type DefendResponseThresholdType string

Type of thresholds used to evaluate the event.

const (
	DefendResponseThresholdTypeCustom    DefendResponseThresholdType = "custom"
	DefendResponseThresholdTypeAutomatic DefendResponseThresholdType = "automatic"
)

func (DefendResponseThresholdType) IsKnown added in v0.12.0

func (r DefendResponseThresholdType) IsKnown() bool

type DefendService

type DefendService struct {
	Options []option.RequestOption
}

DefendService contains methods and other services that help with interacting with the deep rails API.

Note, unlike clients, this service does not read variables from the environment automatically. You should not instantiate this service directly, and instead use the NewDefendService method instead.

func NewDefendService

func NewDefendService(opts ...option.RequestOption) (r *DefendService)

NewDefendService generates a new service that applies the given options to each request. These options are applied after the parent client's options (if there is one), and before any request-specific options.

func (*DefendService) GetEvent

func (r *DefendService) GetEvent(ctx context.Context, workflowID string, eventID string, opts ...option.RequestOption) (res *WorkflowEventDetailResponse, err error)

Use this endpoint to retrieve a specific event of a guardrail workflow

func (*DefendService) GetWorkflow

func (r *DefendService) GetWorkflow(ctx context.Context, workflowID string, query DefendGetWorkflowParams, opts ...option.RequestOption) (res *DefendResponse, err error)

Use this endpoint to retrieve the details for a specific defend workflow

func (*DefendService) NewWorkflow

func (r *DefendService) NewWorkflow(ctx context.Context, body DefendNewWorkflowParams, opts ...option.RequestOption) (res *DefendCreateResponse, err error)

Use this endpoint to create a new guardrail workflow by specifying guardrail thresholds, an improvement action, and optional extended capabilities.

func (*DefendService) SubmitAndStreamEventStreaming added in v0.23.0

func (r *DefendService) SubmitAndStreamEventStreaming(ctx context.Context, workflowID string, params DefendSubmitAndStreamEventParams, opts ...option.RequestOption) (stream *ssestream.Stream[string])

Use this endpoint to submit a model input and output pair to a workflow for evaluation with streaming responses.

func (*DefendService) SubmitEvent

func (r *DefendService) SubmitEvent(ctx context.Context, workflowID string, body DefendSubmitEventParams, opts ...option.RequestOption) (res *WorkflowEventResponse, err error)

Use this endpoint to submit a model input and output pair to a workflow for evaluation

func (*DefendService) UpdateWorkflow

func (r *DefendService) UpdateWorkflow(ctx context.Context, workflowID string, body DefendUpdateWorkflowParams, opts ...option.RequestOption) (res *DefendUpdateResponse, err error)

Use this endpoint to update an existing defend workflow if its details change.

type DefendSubmitAndStreamEventParams added in v0.23.0

type DefendSubmitAndStreamEventParams struct {
	// The input provided to the model (e.g., prompt, messages).
	ModelInput param.Field[map[string]interface{}] `json:"model_input" api:"required"`
	// The output generated by the model to be evaluated.
	ModelOutput param.Field[string] `json:"model_output" api:"required"`
	// The model that generated the output (e.g., "gpt-4", "claude-3").
	ModelUsed param.Field[string] `json:"model_used" api:"required"`
	// The evaluation run mode. Streaming is supported on all run modes except
	// precision_max and precision_max_codex. Note: super_fast does not support Web
	// Search or File Search — if your workflow has these enabled, use a different run
	// mode or disable the capability on the workflow.
	RunMode param.Field[DefendSubmitAndStreamEventParamsRunMode] `json:"run_mode" api:"required"`
	// Enable SSE streaming for real-time token feedback. Supported on all run modes
	// except precision_max and precision_max_codex.
	Stream param.Field[bool] `query:"stream"`
	// Optional tag to identify this event.
	Nametag param.Field[string] `json:"nametag"`
}

func (DefendSubmitAndStreamEventParams) MarshalJSON added in v0.23.0

func (r DefendSubmitAndStreamEventParams) MarshalJSON() (data []byte, err error)

func (DefendSubmitAndStreamEventParams) URLQuery added in v0.23.0

func (r DefendSubmitAndStreamEventParams) URLQuery() (v url.Values)

URLQuery serializes DefendSubmitAndStreamEventParams's query parameters as `url.Values`.

type DefendSubmitAndStreamEventParamsRunMode added in v0.23.0

type DefendSubmitAndStreamEventParamsRunMode string

The evaluation run mode. Streaming is supported on all run modes except precision_max and precision_max_codex. Note: super_fast does not support Web Search or File Search — if your workflow has these enabled, use a different run mode or disable the capability on the workflow.

const (
	DefendSubmitAndStreamEventParamsRunModeSuperFast      DefendSubmitAndStreamEventParamsRunMode = "super_fast"
	DefendSubmitAndStreamEventParamsRunModeFast           DefendSubmitAndStreamEventParamsRunMode = "fast"
	DefendSubmitAndStreamEventParamsRunModePrecision      DefendSubmitAndStreamEventParamsRunMode = "precision"
	DefendSubmitAndStreamEventParamsRunModePrecisionCodex DefendSubmitAndStreamEventParamsRunMode = "precision_codex"
)

func (DefendSubmitAndStreamEventParamsRunMode) IsKnown added in v0.23.0

type DefendSubmitEventParams

type DefendSubmitEventParams struct {
	// A dictionary of inputs sent to the LLM to generate output. The dictionary must
	// contain a `user_prompt` field. For the ground_truth_adherence guardrail metric,
	// `ground_truth` should be provided.
	ModelInput param.Field[DefendSubmitEventParamsModelInput] `json:"model_input" api:"required"`
	// Output generated by the LLM to be evaluated.
	ModelOutput param.Field[string] `json:"model_output" api:"required"`
	// Model ID used to generate the output, like `gpt-4o` or `o3`.
	ModelUsed param.Field[string] `json:"model_used" api:"required"`
	// Run mode for the workflow event. The run mode allows the user to optimize for
	// speed, accuracy, and cost by determining which models are used to evaluate the
	// event. Available run modes (fastest to most thorough): `super_fast`, `fast`,
	// `precision`, `precision_codex`, `precision_max`, and `precision_max_codex`.
	// Defaults to `fast`. Note: `super_fast` does not support Web Search or File
	// Search — if your workflow has these capabilities enabled, use a different run
	// mode or edit the workflow to disable them.
	RunMode param.Field[DefendSubmitEventParamsRunMode] `json:"run_mode" api:"required"`
	// An optional, user-defined tag for the event.
	Nametag param.Field[string] `json:"nametag"`
}

func (DefendSubmitEventParams) MarshalJSON

func (r DefendSubmitEventParams) MarshalJSON() (data []byte, err error)

type DefendSubmitEventParamsModelInput

type DefendSubmitEventParamsModelInput struct {
	// The user prompt used to generate the output.
	UserPrompt param.Field[string] `json:"user_prompt" api:"required"`
	// Any structured information that directly relates to the model’s input and
	// expected output—e.g., the recent turn-by-turn history between an AI tutor and a
	// student, facts or state passed through an agentic workflow, or other
	// domain-specific signals your system already knows and wants the model to
	// condition on.
	Context param.Field[[]DefendSubmitEventParamsModelInputContext] `json:"context"`
	// The ground truth for evaluating the Ground Truth Adherence guardrail.
	GroundTruth param.Field[string] `json:"ground_truth"`
	// The system prompt used to generate the output.
	SystemPrompt param.Field[string] `json:"system_prompt"`
}

A dictionary of inputs sent to the LLM to generate output. The dictionary must contain a `user_prompt` field. For the ground_truth_adherence guardrail metric, `ground_truth` should be provided.

func (DefendSubmitEventParamsModelInput) MarshalJSON

func (r DefendSubmitEventParamsModelInput) MarshalJSON() (data []byte, err error)

type DefendSubmitEventParamsModelInputContext added in v0.22.0

type DefendSubmitEventParamsModelInputContext struct {
	// The content of the message.
	Content param.Field[string] `json:"content"`
	// The role of the speaker.
	Role param.Field[string] `json:"role"`
}

func (DefendSubmitEventParamsModelInputContext) MarshalJSON added in v0.22.0

func (r DefendSubmitEventParamsModelInputContext) MarshalJSON() (data []byte, err error)

type DefendSubmitEventParamsRunMode

type DefendSubmitEventParamsRunMode string

Run mode for the workflow event. The run mode allows the user to optimize for speed, accuracy, and cost by determining which models are used to evaluate the event. Available run modes (fastest to most thorough): `super_fast`, `fast`, `precision`, `precision_codex`, `precision_max`, and `precision_max_codex`. Defaults to `fast`. Note: `super_fast` does not support Web Search or File Search — if your workflow has these capabilities enabled, use a different run mode or edit the workflow to disable them.

const (
	DefendSubmitEventParamsRunModeSuperFast         DefendSubmitEventParamsRunMode = "super_fast"
	DefendSubmitEventParamsRunModeFast              DefendSubmitEventParamsRunMode = "fast"
	DefendSubmitEventParamsRunModePrecision         DefendSubmitEventParamsRunMode = "precision"
	DefendSubmitEventParamsRunModePrecisionCodex    DefendSubmitEventParamsRunMode = "precision_codex"
	DefendSubmitEventParamsRunModePrecisionMax      DefendSubmitEventParamsRunMode = "precision_max"
	DefendSubmitEventParamsRunModePrecisionMaxCodex DefendSubmitEventParamsRunMode = "precision_max_codex"
)

func (DefendSubmitEventParamsRunMode) IsKnown added in v0.2.0

type DefendUpdateResponse added in v0.12.0

type DefendUpdateResponse struct {
	// The time the workflow was last modified in UTC.
	ModifiedAt time.Time `json:"modified_at" api:"required" format:"date-time"`
	// Status of the selected workflow. May be `inactive` or `active`. Inactive
	// workflows will not accept events.
	Status DefendUpdateResponseStatus `json:"status" api:"required"`
	// A unique workflow ID.
	WorkflowID string `json:"workflow_id" api:"required"`
	// The name of the workflow.
	Name string                   `json:"name"`
	JSON defendUpdateResponseJSON `json:"-"`
}

func (*DefendUpdateResponse) UnmarshalJSON added in v0.12.0

func (r *DefendUpdateResponse) UnmarshalJSON(data []byte) (err error)

type DefendUpdateResponseStatus added in v0.12.0

type DefendUpdateResponseStatus string

Status of the selected workflow. May be `inactive` or `active`. Inactive workflows will not accept events.

const (
	DefendUpdateResponseStatusInactive DefendUpdateResponseStatus = "inactive"
	DefendUpdateResponseStatusActive   DefendUpdateResponseStatus = "active"
)

func (DefendUpdateResponseStatus) IsKnown added in v0.12.0

func (r DefendUpdateResponseStatus) IsKnown() bool

type DefendUpdateWorkflowParams

type DefendUpdateWorkflowParams struct {
	// New mapping of guardrail metrics to hallucination tolerance levels (either
	// `low`, `medium`, or `high`) to be used when `threshold_type` is set to
	// `automatic`. Possible metrics are `completeness`, `instruction_adherence`,
	// `context_adherence`, `ground_truth_adherence`, or `comprehensive_safety`.
	AutomaticHallucinationToleranceLevels param.Field[map[string]DefendUpdateWorkflowParamsAutomaticHallucinationToleranceLevels] `json:"automatic_hallucination_tolerance_levels"`
	// Whether to enable context awareness for this workflow's evaluations.
	ContextAwareness param.Field[bool] `json:"context_awareness"`
	// New mapping of guardrail metrics to floating point threshold values to be used
	// when `threshold_type` is set to `custom`. Possible metrics are `correctness`,
	// `completeness`, `instruction_adherence`, `context_adherence`,
	// `ground_truth_adherence`, or `comprehensive_safety`.
	CustomHallucinationThresholdValues param.Field[map[string]float64] `json:"custom_hallucination_threshold_values"`
	// New description for the workflow.
	Description param.Field[string] `json:"description"`
	// An array of file IDs to search in the workflow's evaluations. Files must be
	// uploaded via the DeepRails API first.
	FileSearch param.Field[[]string] `json:"file_search"`
	// The new action used to improve outputs that fail one or more guardrail metrics
	// for the workflow events. May be `regen`, `fixit`, or `do_nothing`. ReGen runs
	// the user's input prompt with minor induced variance. FixIt attempts to directly
	// address the shortcomings of the output using the guardrail failure rationale. Do
	// Nothing does not attempt any improvement.
	ImprovementAction param.Field[DefendUpdateWorkflowParamsImprovementAction] `json:"improvement_action"`
	// Max. number of improvement action attempts until a given event passes the
	// guardrails. Defaults to 10.
	MaxImprovementAttempts param.Field[int64] `json:"max_improvement_attempts"`
	// New name for the workflow.
	Name param.Field[string] `json:"name"`
	// New type of thresholds to use for the workflow, either `automatic` or `custom`.
	// Automatic thresholds are assigned internally after the user specifies a
	// qualitative tolerance for the metrics, whereas custom metrics allow the user to
	// set the threshold for each metric as a floating point number between 0.0 and
	// 1.0.
	ThresholdType param.Field[DefendUpdateWorkflowParamsThresholdType] `json:"threshold_type"`
	// Whether to enable web search for this workflow's evaluations.
	WebSearch param.Field[bool] `json:"web_search"`
}

func (DefendUpdateWorkflowParams) MarshalJSON

func (r DefendUpdateWorkflowParams) MarshalJSON() (data []byte, err error)

type DefendUpdateWorkflowParamsAutomaticHallucinationToleranceLevels added in v0.20.0

type DefendUpdateWorkflowParamsAutomaticHallucinationToleranceLevels string
const (
	DefendUpdateWorkflowParamsAutomaticHallucinationToleranceLevelsLow    DefendUpdateWorkflowParamsAutomaticHallucinationToleranceLevels = "low"
	DefendUpdateWorkflowParamsAutomaticHallucinationToleranceLevelsMedium DefendUpdateWorkflowParamsAutomaticHallucinationToleranceLevels = "medium"
	DefendUpdateWorkflowParamsAutomaticHallucinationToleranceLevelsHigh   DefendUpdateWorkflowParamsAutomaticHallucinationToleranceLevels = "high"
)

func (DefendUpdateWorkflowParamsAutomaticHallucinationToleranceLevels) IsKnown added in v0.20.0

type DefendUpdateWorkflowParamsImprovementAction added in v0.20.0

type DefendUpdateWorkflowParamsImprovementAction string

The new action used to improve outputs that fail one or more guardrail metrics for the workflow events. May be `regen`, `fixit`, or `do_nothing`. ReGen runs the user's input prompt with minor induced variance. FixIt attempts to directly address the shortcomings of the output using the guardrail failure rationale. Do Nothing does not attempt any improvement.

const (
	DefendUpdateWorkflowParamsImprovementActionRegen     DefendUpdateWorkflowParamsImprovementAction = "regen"
	DefendUpdateWorkflowParamsImprovementActionFixit     DefendUpdateWorkflowParamsImprovementAction = "fixit"
	DefendUpdateWorkflowParamsImprovementActionDoNothing DefendUpdateWorkflowParamsImprovementAction = "do_nothing"
)

func (DefendUpdateWorkflowParamsImprovementAction) IsKnown added in v0.20.0

type DefendUpdateWorkflowParamsThresholdType added in v0.20.0

type DefendUpdateWorkflowParamsThresholdType string

New type of thresholds to use for the workflow, either `automatic` or `custom`. Automatic thresholds are assigned internally after the user specifies a qualitative tolerance for the metrics, whereas custom metrics allow the user to set the threshold for each metric as a floating point number between 0.0 and 1.0.

const (
	DefendUpdateWorkflowParamsThresholdTypeAutomatic DefendUpdateWorkflowParamsThresholdType = "automatic"
	DefendUpdateWorkflowParamsThresholdTypeCustom    DefendUpdateWorkflowParamsThresholdType = "custom"
)

func (DefendUpdateWorkflowParamsThresholdType) IsKnown added in v0.20.0

type Error

type Error = apierror.Error

type FileResponse added in v0.10.0

type FileResponse struct {
	// A unique file ID.
	FileID string `json:"file_id"`
	// Name of the file.
	FileName string `json:"file_name"`
	// The size of the file in bytes.
	FileSize int64            `json:"file_size"`
	JSON     fileResponseJSON `json:"-"`
}

func (*FileResponse) UnmarshalJSON added in v0.10.0

func (r *FileResponse) UnmarshalJSON(data []byte) (err error)

type FileService added in v0.10.0

type FileService struct {
	Options []option.RequestOption
}

FileService contains methods and other services that help with interacting with the deep rails API.

Note, unlike clients, this service does not read variables from the environment automatically. You should not instantiate this service directly, and instead use the NewFileService method instead.

func NewFileService added in v0.10.0

func NewFileService(opts ...option.RequestOption) (r *FileService)

NewFileService generates a new service that applies the given options to each request. These options are applied after the parent client's options (if there is one), and before any request-specific options.

func (*FileService) Upload added in v0.10.0

func (r *FileService) Upload(ctx context.Context, body FileUploadParams, opts ...option.RequestOption) (res *FileResponse, err error)

Use this endpoint to upload a file to the DeepRails API

type FileUploadParams added in v0.10.0

type FileUploadParams struct {
	// The contents of the files to upload.
	Files param.Field[[]string] `json:"files" api:"required"`
}

func (FileUploadParams) MarshalMultipart added in v0.10.0

func (r FileUploadParams) MarshalMultipart() (data []byte, contentType string, err error)

type MonitorCreateResponse added in v0.12.0

type MonitorCreateResponse struct {
	// The time the monitor was created in UTC.
	CreatedAt time.Time `json:"created_at" api:"required" format:"date-time"`
	// A unique monitor ID.
	MonitorID string `json:"monitor_id" api:"required"`
	// Status of the monitor. Can be `active` or `inactive`. Inactive monitors no
	// longer record and evaluate events.
	Status MonitorCreateResponseStatus `json:"status" api:"required"`
	JSON   monitorCreateResponseJSON   `json:"-"`
}

func (*MonitorCreateResponse) UnmarshalJSON added in v0.12.0

func (r *MonitorCreateResponse) UnmarshalJSON(data []byte) (err error)

type MonitorCreateResponseStatus added in v0.12.0

type MonitorCreateResponseStatus string

Status of the monitor. Can be `active` or `inactive`. Inactive monitors no longer record and evaluate events.

const (
	MonitorCreateResponseStatusActive   MonitorCreateResponseStatus = "active"
	MonitorCreateResponseStatusInactive MonitorCreateResponseStatus = "inactive"
)

func (MonitorCreateResponseStatus) IsKnown added in v0.12.0

func (r MonitorCreateResponseStatus) IsKnown() bool

type MonitorDetailResponse added in v0.9.0

type MonitorDetailResponse struct {
	// An array of extended AI capabilities associated with this monitor. Can be
	// `web_search`, `file_search`, and/or `context_awareness`.
	Capabilities []MonitorDetailResponseCapability `json:"capabilities" api:"required"`
	// The time the monitor was created in UTC.
	CreatedAt time.Time `json:"created_at" api:"required" format:"date-time"`
	// An array of all evaluations performed by this monitor. Each one corresponds to a
	// separate monitor event.
	Evaluations []MonitorDetailResponseEvaluation `json:"evaluations" api:"required"`
	// An array of files associated with this monitor.
	Files []MonitorDetailResponseFile `json:"files" api:"required"`
	// A unique monitor ID.
	MonitorID string `json:"monitor_id" api:"required"`
	// Name of this monitor.
	Name string `json:"name" api:"required"`
	// Contains five fields used for stats of this monitor: total evaluations,
	// completed evaluations, failed evaluations, queued evaluations, and in progress
	// evaluations.
	Stats MonitorDetailResponseStats `json:"stats" api:"required"`
	// Status of the monitor. Can be `active` or `inactive`. Inactive monitors no
	// longer record and evaluate events.
	Status MonitorDetailResponseStatus `json:"status" api:"required"`
	// The most recent time the monitor was modified in UTC.
	UpdatedAt time.Time `json:"updated_at" api:"required" format:"date-time"`
	// Description of this monitor.
	Description string                    `json:"description"`
	JSON        monitorDetailResponseJSON `json:"-"`
}

func (*MonitorDetailResponse) UnmarshalJSON added in v0.9.0

func (r *MonitorDetailResponse) UnmarshalJSON(data []byte) (err error)

type MonitorDetailResponseCapability added in v0.12.0

type MonitorDetailResponseCapability struct {
	// The type of capability.
	Capability string                              `json:"capability"`
	JSON       monitorDetailResponseCapabilityJSON `json:"-"`
}

func (*MonitorDetailResponseCapability) UnmarshalJSON added in v0.12.0

func (r *MonitorDetailResponseCapability) UnmarshalJSON(data []byte) (err error)

type MonitorDetailResponseEvaluation added in v0.9.0

type MonitorDetailResponseEvaluation struct {
	// Status of the evaluation.
	EvaluationStatus MonitorDetailResponseEvaluationsEvaluationStatus `json:"evaluation_status" api:"required"`
	// A dictionary of inputs sent to the LLM to generate output. The dictionary must
	// contain a `user_prompt` field. For ground_truth_adherence guardrail metric,
	// `ground_truth` should be provided. When `context_awareness` is enabled,
	// `context` should be provided.
	ModelInput MonitorDetailResponseEvaluationsModelInput `json:"model_input" api:"required"`
	// Output generated by the LLM to be evaluated.
	ModelOutput string `json:"model_output" api:"required"`
	// Run mode for the evaluation. The run mode allows the user to optimize for speed,
	// accuracy, and cost by determining which models are used to evaluate the event.
	// Note: `super_fast` do not support Web Search or File Search capabilities.
	RunMode MonitorDetailResponseEvaluationsRunMode `json:"run_mode" api:"required"`
	// The time the evaluation was created in UTC.
	CreatedAt time.Time `json:"created_at" format:"date-time"`
	// Error message if the evaluation failed.
	ErrorMessage string `json:"error_message"`
	// Evaluation result consisting of average scores and rationales for each of the
	// evaluated guardrail metrics.
	EvaluationResult map[string]interface{} `json:"evaluation_result"`
	// Total cost of the evaluation.
	EvaluationTotalCost float64 `json:"evaluation_total_cost"`
	// An array of guardrail metrics that the input and output pair will be evaluated
	// on.
	GuardrailMetrics []MonitorDetailResponseEvaluationsGuardrailMetric `json:"guardrail_metrics"`
	// An optional, user-defined tag for the evaluation.
	Nametag string `json:"nametag"`
	// Evaluation progress. Values range between 0 and 100; 100 corresponds to a
	// completed `evaluation_status`.
	Progress int64                               `json:"progress"`
	JSON     monitorDetailResponseEvaluationJSON `json:"-"`
}

func (*MonitorDetailResponseEvaluation) UnmarshalJSON added in v0.9.0

func (r *MonitorDetailResponseEvaluation) UnmarshalJSON(data []byte) (err error)

type MonitorDetailResponseEvaluationsEvaluationStatus added in v0.9.0

type MonitorDetailResponseEvaluationsEvaluationStatus string

Status of the evaluation.

const (
	MonitorDetailResponseEvaluationsEvaluationStatusInProgress MonitorDetailResponseEvaluationsEvaluationStatus = "in_progress"
	MonitorDetailResponseEvaluationsEvaluationStatusCompleted  MonitorDetailResponseEvaluationsEvaluationStatus = "completed"
	MonitorDetailResponseEvaluationsEvaluationStatusCanceled   MonitorDetailResponseEvaluationsEvaluationStatus = "canceled"
	MonitorDetailResponseEvaluationsEvaluationStatusQueued     MonitorDetailResponseEvaluationsEvaluationStatus = "queued"
	MonitorDetailResponseEvaluationsEvaluationStatusFailed     MonitorDetailResponseEvaluationsEvaluationStatus = "failed"
)

func (MonitorDetailResponseEvaluationsEvaluationStatus) IsKnown added in v0.9.0

type MonitorDetailResponseEvaluationsGuardrailMetric added in v0.9.0

type MonitorDetailResponseEvaluationsGuardrailMetric string
const (
	MonitorDetailResponseEvaluationsGuardrailMetricCorrectness          MonitorDetailResponseEvaluationsGuardrailMetric = "correctness"
	MonitorDetailResponseEvaluationsGuardrailMetricCompleteness         MonitorDetailResponseEvaluationsGuardrailMetric = "completeness"
	MonitorDetailResponseEvaluationsGuardrailMetricInstructionAdherence MonitorDetailResponseEvaluationsGuardrailMetric = "instruction_adherence"
	MonitorDetailResponseEvaluationsGuardrailMetricContextAdherence     MonitorDetailResponseEvaluationsGuardrailMetric = "context_adherence"
	MonitorDetailResponseEvaluationsGuardrailMetricGroundTruthAdherence MonitorDetailResponseEvaluationsGuardrailMetric = "ground_truth_adherence"
	MonitorDetailResponseEvaluationsGuardrailMetricComprehensiveSafety  MonitorDetailResponseEvaluationsGuardrailMetric = "comprehensive_safety"
)

func (MonitorDetailResponseEvaluationsGuardrailMetric) IsKnown added in v0.9.0

type MonitorDetailResponseEvaluationsModelInput added in v0.9.0

type MonitorDetailResponseEvaluationsModelInput struct {
	// The user prompt used to generate the output.
	UserPrompt string `json:"user_prompt" api:"required"`
	// Any structured information that directly relates to the model’s input and
	// expected output—e.g., the recent turn-by-turn history between an AI tutor and a
	// student, facts or state passed through an agentic workflow, or other
	// domain-specific signals your system already knows and wants the model to
	// condition on.
	Context []MonitorDetailResponseEvaluationsModelInputContext `json:"context"`
	// The ground truth for evaluating Ground Truth Adherence guardrail.
	GroundTruth string `json:"ground_truth"`
	// The system prompt used to generate the output.
	SystemPrompt string                                         `json:"system_prompt"`
	JSON         monitorDetailResponseEvaluationsModelInputJSON `json:"-"`
}

A dictionary of inputs sent to the LLM to generate output. The dictionary must contain a `user_prompt` field. For ground_truth_adherence guardrail metric, `ground_truth` should be provided. When `context_awareness` is enabled, `context` should be provided.

func (*MonitorDetailResponseEvaluationsModelInput) UnmarshalJSON added in v0.9.0

func (r *MonitorDetailResponseEvaluationsModelInput) UnmarshalJSON(data []byte) (err error)

type MonitorDetailResponseEvaluationsModelInputContext added in v0.22.0

type MonitorDetailResponseEvaluationsModelInputContext struct {
	// The content of the message.
	Content string `json:"content"`
	// The role of the speaker.
	Role string                                                `json:"role"`
	JSON monitorDetailResponseEvaluationsModelInputContextJSON `json:"-"`
}

func (*MonitorDetailResponseEvaluationsModelInputContext) UnmarshalJSON added in v0.22.0

func (r *MonitorDetailResponseEvaluationsModelInputContext) UnmarshalJSON(data []byte) (err error)

type MonitorDetailResponseEvaluationsRunMode added in v0.9.0

type MonitorDetailResponseEvaluationsRunMode string

Run mode for the evaluation. The run mode allows the user to optimize for speed, accuracy, and cost by determining which models are used to evaluate the event. Note: `super_fast` do not support Web Search or File Search capabilities.

const (
	MonitorDetailResponseEvaluationsRunModeSuperFast         MonitorDetailResponseEvaluationsRunMode = "super_fast"
	MonitorDetailResponseEvaluationsRunModeFast              MonitorDetailResponseEvaluationsRunMode = "fast"
	MonitorDetailResponseEvaluationsRunModePrecision         MonitorDetailResponseEvaluationsRunMode = "precision"
	MonitorDetailResponseEvaluationsRunModePrecisionCodex    MonitorDetailResponseEvaluationsRunMode = "precision_codex"
	MonitorDetailResponseEvaluationsRunModePrecisionMax      MonitorDetailResponseEvaluationsRunMode = "precision_max"
	MonitorDetailResponseEvaluationsRunModePrecisionMaxCodex MonitorDetailResponseEvaluationsRunMode = "precision_max_codex"
)

func (MonitorDetailResponseEvaluationsRunMode) IsKnown added in v0.9.0

type MonitorDetailResponseFile added in v0.12.0

type MonitorDetailResponseFile struct {
	// The ID of the file.
	FileID string `json:"file_id"`
	// The name of the file.
	FileName string `json:"file_name"`
	// The size of the file in bytes.
	FileSize int64                         `json:"file_size"`
	JSON     monitorDetailResponseFileJSON `json:"-"`
}

func (*MonitorDetailResponseFile) UnmarshalJSON added in v0.12.0

func (r *MonitorDetailResponseFile) UnmarshalJSON(data []byte) (err error)

type MonitorDetailResponseStats added in v0.9.0

type MonitorDetailResponseStats struct {
	// Number of evaluations that completed successfully.
	CompletedEvaluations int64 `json:"completed_evaluations"`
	// Number of evaluations that failed.
	FailedEvaluations int64 `json:"failed_evaluations"`
	// Number of evaluations currently in progress.
	InProgressEvaluations int64 `json:"in_progress_evaluations"`
	// Number of evaluations currently queued.
	QueuedEvaluations int64 `json:"queued_evaluations"`
	// Total number of evaluations performed by this monitor.
	TotalEvaluations int64                          `json:"total_evaluations"`
	JSON             monitorDetailResponseStatsJSON `json:"-"`
}

Contains five fields used for stats of this monitor: total evaluations, completed evaluations, failed evaluations, queued evaluations, and in progress evaluations.

func (*MonitorDetailResponseStats) UnmarshalJSON added in v0.9.0

func (r *MonitorDetailResponseStats) UnmarshalJSON(data []byte) (err error)

type MonitorDetailResponseStatus added in v0.12.0

type MonitorDetailResponseStatus string

Status of the monitor. Can be `active` or `inactive`. Inactive monitors no longer record and evaluate events.

const (
	MonitorDetailResponseStatusActive   MonitorDetailResponseStatus = "active"
	MonitorDetailResponseStatusInactive MonitorDetailResponseStatus = "inactive"
)

func (MonitorDetailResponseStatus) IsKnown added in v0.12.0

func (r MonitorDetailResponseStatus) IsKnown() bool

type MonitorEventDetailResponse added in v0.13.0

type MonitorEventDetailResponse struct {
	// The extended AI capabilities associated with the monitor event. Can be
	// `web_search`, `file_search`, and/or `context_awareness`.
	Capabilities []MonitorEventDetailResponseCapability `json:"capabilities"`
	// The time spent on the evaluation in seconds.
	EvalTime string `json:"eval_time"`
	// The result of the evaluation of the monitor event.
	EvaluationResult map[string]interface{} `json:"evaluation_result"`
	// A unique monitor event ID.
	EventID string `json:"event_id"`
	// The files associated with the monitor event.
	Files []MonitorEventDetailResponseFile `json:"files"`
	// The guardrail metrics evaluated by the monitor event.
	GuardrailMetrics []string `json:"guardrail_metrics"`
	// The model input used to create the monitor event.
	ModelInput map[string]interface{} `json:"model_input"`
	// The output evaluated by the monitor event.
	ModelOutput string `json:"model_output"`
	// Monitor ID associated with this event.
	MonitorID string `json:"monitor_id"`
	// A human-readable tag for the monitor event.
	Nametag string `json:"nametag"`
	// The run mode used to evaluate the monitor event.
	RunMode MonitorEventDetailResponseRunMode `json:"run_mode"`
	// Status of the monitor event's evaluation.
	Status MonitorEventDetailResponseStatus `json:"status"`
	// The time the monitor event was created in UTC.
	Timestamp time.Time                      `json:"timestamp" format:"date-time"`
	JSON      monitorEventDetailResponseJSON `json:"-"`
}

func (*MonitorEventDetailResponse) UnmarshalJSON added in v0.13.0

func (r *MonitorEventDetailResponse) UnmarshalJSON(data []byte) (err error)

type MonitorEventDetailResponseCapability added in v0.13.0

type MonitorEventDetailResponseCapability struct {
	// The type of capability.
	Capability string                                   `json:"capability"`
	JSON       monitorEventDetailResponseCapabilityJSON `json:"-"`
}

func (*MonitorEventDetailResponseCapability) UnmarshalJSON added in v0.13.0

func (r *MonitorEventDetailResponseCapability) UnmarshalJSON(data []byte) (err error)

type MonitorEventDetailResponseFile added in v0.13.0

type MonitorEventDetailResponseFile struct {
	// The ID of the file.
	FileID string `json:"file_id"`
	// The name of the file.
	FileName string `json:"file_name"`
	// The size of the file in bytes.
	FileSize int64                              `json:"file_size"`
	JSON     monitorEventDetailResponseFileJSON `json:"-"`
}

func (*MonitorEventDetailResponseFile) UnmarshalJSON added in v0.13.0

func (r *MonitorEventDetailResponseFile) UnmarshalJSON(data []byte) (err error)

type MonitorEventDetailResponseRunMode added in v0.13.0

type MonitorEventDetailResponseRunMode string

The run mode used to evaluate the monitor event.

const (
	MonitorEventDetailResponseRunModeSuperFast         MonitorEventDetailResponseRunMode = "super_fast"
	MonitorEventDetailResponseRunModeFast              MonitorEventDetailResponseRunMode = "fast"
	MonitorEventDetailResponseRunModePrecision         MonitorEventDetailResponseRunMode = "precision"
	MonitorEventDetailResponseRunModePrecisionCodex    MonitorEventDetailResponseRunMode = "precision_codex"
	MonitorEventDetailResponseRunModePrecisionMax      MonitorEventDetailResponseRunMode = "precision_max"
	MonitorEventDetailResponseRunModePrecisionMaxCodex MonitorEventDetailResponseRunMode = "precision_max_codex"
)

func (MonitorEventDetailResponseRunMode) IsKnown added in v0.13.0

type MonitorEventDetailResponseStatus added in v0.13.0

type MonitorEventDetailResponseStatus string

Status of the monitor event's evaluation.

const (
	MonitorEventDetailResponseStatusInProgress MonitorEventDetailResponseStatus = "in_progress"
	MonitorEventDetailResponseStatusCompleted  MonitorEventDetailResponseStatus = "completed"
	MonitorEventDetailResponseStatusCanceled   MonitorEventDetailResponseStatus = "canceled"
	MonitorEventDetailResponseStatusQueued     MonitorEventDetailResponseStatus = "queued"
	MonitorEventDetailResponseStatusFailed     MonitorEventDetailResponseStatus = "failed"
)

func (MonitorEventDetailResponseStatus) IsKnown added in v0.13.0

type MonitorEventResponse added in v0.9.0

type MonitorEventResponse struct {
	// A unique monitor event ID.
	EventID string `json:"event_id" api:"required"`
	// Monitor ID associated with this event.
	MonitorID string `json:"monitor_id" api:"required"`
	// The time the monitor event was created in UTC.
	CreatedAt time.Time                `json:"created_at" format:"date-time"`
	JSON      monitorEventResponseJSON `json:"-"`
}

func (*MonitorEventResponse) UnmarshalJSON added in v0.9.0

func (r *MonitorEventResponse) UnmarshalJSON(data []byte) (err error)

type MonitorGetParams

type MonitorGetParams struct {
	// Limit the number of returned evaluations associated with this monitor. Defaults
	// to 10.
	Limit param.Field[int64] `query:"limit"`
}

func (MonitorGetParams) URLQuery

func (r MonitorGetParams) URLQuery() (v url.Values)

URLQuery serializes MonitorGetParams's query parameters as `url.Values`.

type MonitorNewParams

type MonitorNewParams struct {
	// An array of guardrail metrics that the model input and output pair will be
	// evaluated on. For non-enterprise users, these will be limited to `correctness`,
	// `completeness`, `instruction_adherence`, `context_adherence`,
	// `ground_truth_adherence`, and/or `comprehensive_safety`.
	GuardrailMetrics param.Field[[]MonitorNewParamsGuardrailMetric] `json:"guardrail_metrics" api:"required"`
	// Name of the new monitor.
	Name param.Field[string] `json:"name" api:"required"`
	// Context includes any structured information that directly relates to the model’s
	// input and expected output—e.g., the recent turn-by-turn history between an AI
	// tutor and a student, facts or state passed through an agentic workflow, or other
	// domain-specific signals your system already knows and wants the model to
	// condition on. This field determines whether to enable context awareness for this
	// monitor's evaluations. Defaults to false.
	ContextAwareness param.Field[bool] `json:"context_awareness"`
	// Description of the new monitor.
	Description param.Field[string] `json:"description"`
	// An array of file IDs to search in the monitor's evaluations. Files must be
	// uploaded via the DeepRails API first.
	FileSearch param.Field[[]string] `json:"file_search"`
	// Whether to enable web search for this monitor's evaluations. Defaults to false.
	WebSearch param.Field[bool] `json:"web_search"`
}

func (MonitorNewParams) MarshalJSON

func (r MonitorNewParams) MarshalJSON() (data []byte, err error)

type MonitorNewParamsGuardrailMetric added in v0.11.0

type MonitorNewParamsGuardrailMetric string
const (
	MonitorNewParamsGuardrailMetricCorrectness          MonitorNewParamsGuardrailMetric = "correctness"
	MonitorNewParamsGuardrailMetricCompleteness         MonitorNewParamsGuardrailMetric = "completeness"
	MonitorNewParamsGuardrailMetricInstructionAdherence MonitorNewParamsGuardrailMetric = "instruction_adherence"
	MonitorNewParamsGuardrailMetricContextAdherence     MonitorNewParamsGuardrailMetric = "context_adherence"
	MonitorNewParamsGuardrailMetricGroundTruthAdherence MonitorNewParamsGuardrailMetric = "ground_truth_adherence"
	MonitorNewParamsGuardrailMetricComprehensiveSafety  MonitorNewParamsGuardrailMetric = "comprehensive_safety"
)

func (MonitorNewParamsGuardrailMetric) IsKnown added in v0.11.0

type MonitorService

type MonitorService struct {
	Options []option.RequestOption
}

MonitorService contains methods and other services that help with interacting with the deep rails API.

Note, unlike clients, this service does not read variables from the environment automatically. You should not instantiate this service directly, and instead use the NewMonitorService method instead.

func NewMonitorService

func NewMonitorService(opts ...option.RequestOption) (r *MonitorService)

NewMonitorService generates a new service that applies the given options to each request. These options are applied after the parent client's options (if there is one), and before any request-specific options.

func (*MonitorService) Get

func (r *MonitorService) Get(ctx context.Context, monitorID string, query MonitorGetParams, opts ...option.RequestOption) (res *MonitorDetailResponse, err error)

Use this endpoint to retrieve the details and evaluations associated with a specific monitor

func (*MonitorService) GetEvent added in v0.13.0

func (r *MonitorService) GetEvent(ctx context.Context, monitorID string, eventID string, opts ...option.RequestOption) (res *MonitorEventDetailResponse, err error)

Use this endpoint to retrieve the details of a specific monitor event

func (*MonitorService) New

Use this endpoint to create a new monitor to evaluate model inputs and outputs using guardrails

func (*MonitorService) SubmitEvent

func (r *MonitorService) SubmitEvent(ctx context.Context, monitorID string, body MonitorSubmitEventParams, opts ...option.RequestOption) (res *MonitorEventResponse, err error)

Use this endpoint to submit a model input and output pair to a monitor for evaluation

func (*MonitorService) Update

func (r *MonitorService) Update(ctx context.Context, monitorID string, body MonitorUpdateParams, opts ...option.RequestOption) (res *MonitorUpdateResponse, err error)

Use this endpoint to update the name, status, and/or other details of an existing monitor.

type MonitorSubmitEventParams

type MonitorSubmitEventParams struct {
	// A dictionary of inputs sent to the LLM to generate output. The dictionary must
	// contain a `user_prompt` field. For ground_truth_adherence guardrail metric,
	// `ground_truth` should be provided.
	ModelInput param.Field[MonitorSubmitEventParamsModelInput] `json:"model_input" api:"required"`
	// Output generated by the LLM to be evaluated.
	ModelOutput param.Field[string] `json:"model_output" api:"required"`
	// An optional, user-defined tag for the event.
	Nametag param.Field[string] `json:"nametag"`
	// Run mode for the monitor event. The run mode allows the user to optimize for
	// speed, accuracy, and cost by determining which models are used to evaluate the
	// event. Available run modes (fastest to most thorough): `super_fast`, `fast`,
	// `precision`, `precision_codex`, `precision_max`, and `precision_max_codex`.
	// Defaults to `fast`. Note: `super_fast` does not support Web Search or File
	// Search — if your monitor has these capabilities enabled, use a different run
	// mode or edit the monitor to disable them.
	RunMode param.Field[MonitorSubmitEventParamsRunMode] `json:"run_mode"`
}

func (MonitorSubmitEventParams) MarshalJSON

func (r MonitorSubmitEventParams) MarshalJSON() (data []byte, err error)

type MonitorSubmitEventParamsModelInput

type MonitorSubmitEventParamsModelInput struct {
	// The user prompt used to generate the output.
	UserPrompt param.Field[string] `json:"user_prompt" api:"required"`
	// Any structured information that directly relates to the model’s input and
	// expected output—e.g., the recent turn-by-turn history between an AI tutor and a
	// student, facts or state passed through an agentic workflow, or other
	// domain-specific signals your system already knows and wants the model to
	// condition on.
	Context param.Field[[]MonitorSubmitEventParamsModelInputContext] `json:"context"`
	// The ground truth for evaluating Ground Truth Adherence guardrail.
	GroundTruth param.Field[string] `json:"ground_truth"`
	// The system prompt used to generate the output.
	SystemPrompt param.Field[string] `json:"system_prompt"`
}

A dictionary of inputs sent to the LLM to generate output. The dictionary must contain a `user_prompt` field. For ground_truth_adherence guardrail metric, `ground_truth` should be provided.

func (MonitorSubmitEventParamsModelInput) MarshalJSON

func (r MonitorSubmitEventParamsModelInput) MarshalJSON() (data []byte, err error)

type MonitorSubmitEventParamsModelInputContext added in v0.22.0

type MonitorSubmitEventParamsModelInputContext struct {
	// The content of the message.
	Content param.Field[string] `json:"content"`
	// The role of the speaker.
	Role param.Field[string] `json:"role"`
}

func (MonitorSubmitEventParamsModelInputContext) MarshalJSON added in v0.22.0

func (r MonitorSubmitEventParamsModelInputContext) MarshalJSON() (data []byte, err error)

type MonitorSubmitEventParamsRunMode

type MonitorSubmitEventParamsRunMode string

Run mode for the monitor event. The run mode allows the user to optimize for speed, accuracy, and cost by determining which models are used to evaluate the event. Available run modes (fastest to most thorough): `super_fast`, `fast`, `precision`, `precision_codex`, `precision_max`, and `precision_max_codex`. Defaults to `fast`. Note: `super_fast` does not support Web Search or File Search — if your monitor has these capabilities enabled, use a different run mode or edit the monitor to disable them.

const (
	MonitorSubmitEventParamsRunModeSuperFast         MonitorSubmitEventParamsRunMode = "super_fast"
	MonitorSubmitEventParamsRunModeFast              MonitorSubmitEventParamsRunMode = "fast"
	MonitorSubmitEventParamsRunModePrecision         MonitorSubmitEventParamsRunMode = "precision"
	MonitorSubmitEventParamsRunModePrecisionCodex    MonitorSubmitEventParamsRunMode = "precision_codex"
	MonitorSubmitEventParamsRunModePrecisionMax      MonitorSubmitEventParamsRunMode = "precision_max"
	MonitorSubmitEventParamsRunModePrecisionMaxCodex MonitorSubmitEventParamsRunMode = "precision_max_codex"
)

func (MonitorSubmitEventParamsRunMode) IsKnown added in v0.2.0

type MonitorUpdateParams

type MonitorUpdateParams struct {
	// New description of the monitor.
	Description param.Field[string] `json:"description"`
	// An array of file IDs to search in the monitor's evaluations. Files must be
	// uploaded via the DeepRails API first.
	FileSearch param.Field[[]string] `json:"file_search"`
	// An array of the new guardrail metrics that model input and output pairs will be
	// evaluated on.
	GuardrailMetrics param.Field[[]MonitorUpdateParamsGuardrailMetric] `json:"guardrail_metrics"`
	// New name of the monitor.
	Name param.Field[string] `json:"name"`
	// Status of the monitor. Can be `active` or `inactive`. Inactive monitors no
	// longer record and evaluate events.
	Status param.Field[MonitorUpdateParamsStatus] `json:"status"`
	// Whether to enable web search for this monitor's evaluations.
	WebSearch param.Field[bool] `json:"web_search"`
}

func (MonitorUpdateParams) MarshalJSON

func (r MonitorUpdateParams) MarshalJSON() (data []byte, err error)

type MonitorUpdateParamsGuardrailMetric added in v0.20.0

type MonitorUpdateParamsGuardrailMetric string
const (
	MonitorUpdateParamsGuardrailMetricCorrectness          MonitorUpdateParamsGuardrailMetric = "correctness"
	MonitorUpdateParamsGuardrailMetricCompleteness         MonitorUpdateParamsGuardrailMetric = "completeness"
	MonitorUpdateParamsGuardrailMetricInstructionAdherence MonitorUpdateParamsGuardrailMetric = "instruction_adherence"
	MonitorUpdateParamsGuardrailMetricContextAdherence     MonitorUpdateParamsGuardrailMetric = "context_adherence"
	MonitorUpdateParamsGuardrailMetricGroundTruthAdherence MonitorUpdateParamsGuardrailMetric = "ground_truth_adherence"
	MonitorUpdateParamsGuardrailMetricComprehensiveSafety  MonitorUpdateParamsGuardrailMetric = "comprehensive_safety"
)

func (MonitorUpdateParamsGuardrailMetric) IsKnown added in v0.20.0

type MonitorUpdateParamsStatus added in v0.12.0

type MonitorUpdateParamsStatus string

Status of the monitor. Can be `active` or `inactive`. Inactive monitors no longer record and evaluate events.

const (
	MonitorUpdateParamsStatusActive   MonitorUpdateParamsStatus = "active"
	MonitorUpdateParamsStatusInactive MonitorUpdateParamsStatus = "inactive"
)

func (MonitorUpdateParamsStatus) IsKnown added in v0.12.0

func (r MonitorUpdateParamsStatus) IsKnown() bool

type MonitorUpdateResponse added in v0.12.0

type MonitorUpdateResponse struct {
	// The time the monitor was last modified in UTC.
	ModifiedAt time.Time `json:"modified_at" api:"required" format:"date-time"`
	// A unique monitor ID.
	MonitorID string `json:"monitor_id" api:"required"`
	// Status of the monitor. Can be `active` or `inactive`. Inactive monitors no
	// longer record and evaluate events.
	Status MonitorUpdateResponseStatus `json:"status" api:"required"`
	JSON   monitorUpdateResponseJSON   `json:"-"`
}

func (*MonitorUpdateResponse) UnmarshalJSON added in v0.12.0

func (r *MonitorUpdateResponse) UnmarshalJSON(data []byte) (err error)

type MonitorUpdateResponseStatus added in v0.12.0

type MonitorUpdateResponseStatus string

Status of the monitor. Can be `active` or `inactive`. Inactive monitors no longer record and evaluate events.

const (
	MonitorUpdateResponseStatusActive   MonitorUpdateResponseStatus = "active"
	MonitorUpdateResponseStatusInactive MonitorUpdateResponseStatus = "inactive"
)

func (MonitorUpdateResponseStatus) IsKnown added in v0.12.0

func (r MonitorUpdateResponseStatus) IsKnown() bool

type WorkflowEventDetailResponse added in v0.12.0

type WorkflowEventDetailResponse struct {
	AnalysisOfFailures []string `json:"analysis_of_failures" api:"required"`
	// History of evaluations for the event.
	EvaluationHistory []WorkflowEventDetailResponseEvaluationHistory `json:"evaluation_history" api:"required"`
	// Evaluation result consisting of average scores and rationales for each of the
	// evaluated guardrail metrics.
	EvaluationResult map[string]interface{} `json:"evaluation_result" api:"required"`
	// A unique workflow event ID.
	EventID string `json:"event_id" api:"required"`
	// Whether the event was filtered and requires improvement.
	Filtered bool `json:"filtered" api:"required"`
	// Improved model output after improvement tool was applied and each metric passed
	// evaluation.
	ImprovedModelOutput string `json:"improved_model_output" api:"required"`
	// Type of improvement action used to improve the event.
	ImprovementAction WorkflowEventDetailResponseImprovementAction `json:"improvement_action" api:"required"`
	// Status of the improvement tool used to improve the event. `improvement_required`
	// indicates that the evaluation is complete and the improvement action is needed
	// but is not taking place. `improved` and `improvement_failed` indicate when the
	// improvement action concludes, successfully and unsuccessfully, respectively.
	// `no_improvement_required` means that the first evaluation passed all its
	// metrics!
	ImprovementToolStatus WorkflowEventDetailResponseImprovementToolStatus `json:"improvement_tool_status" api:"required,nullable"`
	KeyImprovements       []WorkflowEventDetailResponseKeyImprovement      `json:"key_improvements" api:"required"`
	// Status of the event.
	Status WorkflowEventDetailResponseStatus `json:"status" api:"required"`
	// Type of thresholds used to evaluate the event.
	ThresholdType WorkflowEventDetailResponseThresholdType `json:"threshold_type" api:"required"`
	// Workflow ID associated with the event.
	WorkflowID string `json:"workflow_id" api:"required"`
	// Mapping of guardrail metric names to tolerance values. Values are strings
	// (`low`, `medium`, `high`) representing automatic tolerance levels.
	AutomaticHallucinationToleranceLevels map[string]WorkflowEventDetailResponseAutomaticHallucinationToleranceLevel `json:"automatic_hallucination_tolerance_levels"`
	// Extended AI capabilities available to the event, if any. Can be `web_search`,
	// `file_search`, and/or `context_awareness`.
	Capabilities []WorkflowEventDetailResponseCapability `json:"capabilities"`
	// Mapping of guardrail metric names to threshold values. Values are floating point
	// numbers (0.0-1.0) representing custom thresholds.
	CustomHallucinationThresholdValues map[string]float64 `json:"custom_hallucination_threshold_values"`
	// List of files available to the event, if any. Will only be present if
	// `file_search` is enabled.
	Files []WorkflowEventDetailResponseFile `json:"files"`
	// The maximum number of improvement attempts to be applied to one event before it
	// is considered failed.
	MaxImprovementAttempts int64                           `json:"max_improvement_attempts"`
	JSON                   workflowEventDetailResponseJSON `json:"-"`
}

func (*WorkflowEventDetailResponse) UnmarshalJSON added in v0.12.0

func (r *WorkflowEventDetailResponse) UnmarshalJSON(data []byte) (err error)

type WorkflowEventDetailResponseAutomaticHallucinationToleranceLevel added in v0.12.0

type WorkflowEventDetailResponseAutomaticHallucinationToleranceLevel string
const (
	WorkflowEventDetailResponseAutomaticHallucinationToleranceLevelLow    WorkflowEventDetailResponseAutomaticHallucinationToleranceLevel = "low"
	WorkflowEventDetailResponseAutomaticHallucinationToleranceLevelMedium WorkflowEventDetailResponseAutomaticHallucinationToleranceLevel = "medium"
	WorkflowEventDetailResponseAutomaticHallucinationToleranceLevelHigh   WorkflowEventDetailResponseAutomaticHallucinationToleranceLevel = "high"
)

func (WorkflowEventDetailResponseAutomaticHallucinationToleranceLevel) IsKnown added in v0.12.0

type WorkflowEventDetailResponseCapability added in v0.12.0

type WorkflowEventDetailResponseCapability struct {
	Capability string                                    `json:"capability"`
	JSON       workflowEventDetailResponseCapabilityJSON `json:"-"`
}

func (*WorkflowEventDetailResponseCapability) UnmarshalJSON added in v0.12.0

func (r *WorkflowEventDetailResponseCapability) UnmarshalJSON(data []byte) (err error)

type WorkflowEventDetailResponseEvaluationHistory added in v0.12.0

type WorkflowEventDetailResponseEvaluationHistory struct {
	AnalysisOfFailures    string                                                            `json:"analysis_of_failures"`
	Attempt               string                                                            `json:"attempt"`
	CreatedAt             time.Time                                                         `json:"created_at" format:"date-time"`
	ErrorMessage          string                                                            `json:"error_message"`
	EvaluationResult      map[string]interface{}                                            `json:"evaluation_result"`
	EvaluationStatus      string                                                            `json:"evaluation_status"`
	EvaluationTotalCost   float64                                                           `json:"evaluation_total_cost"`
	GuardrailMetrics      []string                                                          `json:"guardrail_metrics"`
	ImprovementToolStatus WorkflowEventDetailResponseEvaluationHistoryImprovementToolStatus `json:"improvement_tool_status"`
	KeyImprovements       []string                                                          `json:"key_improvements"`
	ModelInput            map[string]interface{}                                            `json:"model_input"`
	ModelOutput           string                                                            `json:"model_output"`
	Nametag               string                                                            `json:"nametag"`
	Progress              int64                                                             `json:"progress"`
	RunMode               string                                                            `json:"run_mode"`
	JSON                  workflowEventDetailResponseEvaluationHistoryJSON                  `json:"-"`
}

func (*WorkflowEventDetailResponseEvaluationHistory) UnmarshalJSON added in v0.12.0

func (r *WorkflowEventDetailResponseEvaluationHistory) UnmarshalJSON(data []byte) (err error)

type WorkflowEventDetailResponseEvaluationHistoryImprovementToolStatus added in v0.22.0

type WorkflowEventDetailResponseEvaluationHistoryImprovementToolStatus string
const (
	WorkflowEventDetailResponseEvaluationHistoryImprovementToolStatusImproved              WorkflowEventDetailResponseEvaluationHistoryImprovementToolStatus = "improved"
	WorkflowEventDetailResponseEvaluationHistoryImprovementToolStatusImprovementFailed     WorkflowEventDetailResponseEvaluationHistoryImprovementToolStatus = "improvement_failed"
	WorkflowEventDetailResponseEvaluationHistoryImprovementToolStatusNoImprovementRequired WorkflowEventDetailResponseEvaluationHistoryImprovementToolStatus = "no_improvement_required"
	WorkflowEventDetailResponseEvaluationHistoryImprovementToolStatusImprovementRequired   WorkflowEventDetailResponseEvaluationHistoryImprovementToolStatus = "improvement_required"
)

func (WorkflowEventDetailResponseEvaluationHistoryImprovementToolStatus) IsKnown added in v0.22.0

type WorkflowEventDetailResponseFile added in v0.12.0

type WorkflowEventDetailResponseFile struct {
	FileID                string                              `json:"file_id"`
	FileName              string                              `json:"file_name"`
	FileSize              int64                               `json:"file_size"`
	PresignedURL          string                              `json:"presigned_url"`
	PresignedURLExpiresAt time.Time                           `json:"presigned_url_expires_at" format:"date-time"`
	JSON                  workflowEventDetailResponseFileJSON `json:"-"`
}

func (*WorkflowEventDetailResponseFile) UnmarshalJSON added in v0.12.0

func (r *WorkflowEventDetailResponseFile) UnmarshalJSON(data []byte) (err error)

type WorkflowEventDetailResponseImprovementAction added in v0.14.0

type WorkflowEventDetailResponseImprovementAction string

Type of improvement action used to improve the event.

const (
	WorkflowEventDetailResponseImprovementActionRegen     WorkflowEventDetailResponseImprovementAction = "regen"
	WorkflowEventDetailResponseImprovementActionFixit     WorkflowEventDetailResponseImprovementAction = "fixit"
	WorkflowEventDetailResponseImprovementActionDoNothing WorkflowEventDetailResponseImprovementAction = "do_nothing"
)

func (WorkflowEventDetailResponseImprovementAction) IsKnown added in v0.14.0

type WorkflowEventDetailResponseImprovementToolStatus added in v0.12.0

type WorkflowEventDetailResponseImprovementToolStatus string

Status of the improvement tool used to improve the event. `improvement_required` indicates that the evaluation is complete and the improvement action is needed but is not taking place. `improved` and `improvement_failed` indicate when the improvement action concludes, successfully and unsuccessfully, respectively. `no_improvement_required` means that the first evaluation passed all its metrics!

const (
	WorkflowEventDetailResponseImprovementToolStatusImproved              WorkflowEventDetailResponseImprovementToolStatus = "improved"
	WorkflowEventDetailResponseImprovementToolStatusImprovementFailed     WorkflowEventDetailResponseImprovementToolStatus = "improvement_failed"
	WorkflowEventDetailResponseImprovementToolStatusNoImprovementRequired WorkflowEventDetailResponseImprovementToolStatus = "no_improvement_required"
	WorkflowEventDetailResponseImprovementToolStatusImprovementRequired   WorkflowEventDetailResponseImprovementToolStatus = "improvement_required"
)

func (WorkflowEventDetailResponseImprovementToolStatus) IsKnown added in v0.12.0

type WorkflowEventDetailResponseKeyImprovement added in v0.24.0

type WorkflowEventDetailResponseKeyImprovement struct {
	KeyImprovement []string                                      `json:"key_improvement"`
	JSON           workflowEventDetailResponseKeyImprovementJSON `json:"-"`
}

func (*WorkflowEventDetailResponseKeyImprovement) UnmarshalJSON added in v0.24.0

func (r *WorkflowEventDetailResponseKeyImprovement) UnmarshalJSON(data []byte) (err error)

type WorkflowEventDetailResponseStatus added in v0.17.0

type WorkflowEventDetailResponseStatus string

Status of the event.

const (
	WorkflowEventDetailResponseStatusInProgress WorkflowEventDetailResponseStatus = "In Progress"
	WorkflowEventDetailResponseStatusCompleted  WorkflowEventDetailResponseStatus = "Completed"
)

func (WorkflowEventDetailResponseStatus) IsKnown added in v0.17.0

type WorkflowEventDetailResponseThresholdType added in v0.12.0

type WorkflowEventDetailResponseThresholdType string

Type of thresholds used to evaluate the event.

const (
	WorkflowEventDetailResponseThresholdTypeCustom    WorkflowEventDetailResponseThresholdType = "custom"
	WorkflowEventDetailResponseThresholdTypeAutomatic WorkflowEventDetailResponseThresholdType = "automatic"
)

func (WorkflowEventDetailResponseThresholdType) IsKnown added in v0.12.0

type WorkflowEventResponse

type WorkflowEventResponse struct {
	// The ID of the billing request for the event.
	BillingRequestID string `json:"billing_request_id" api:"required"`
	// The time the event was created in UTC.
	CreatedAt time.Time `json:"created_at" api:"required" format:"date-time"`
	// A unique workflow event ID.
	EventID string `json:"event_id" api:"required"`
	// Status of the event.
	Status WorkflowEventResponseStatus `json:"status" api:"required"`
	// Workflow ID associated with the event.
	WorkflowID string                    `json:"workflow_id" api:"required"`
	JSON       workflowEventResponseJSON `json:"-"`
}

func (*WorkflowEventResponse) UnmarshalJSON

func (r *WorkflowEventResponse) UnmarshalJSON(data []byte) (err error)

type WorkflowEventResponseStatus added in v0.12.0

type WorkflowEventResponseStatus string

Status of the event.

const (
	WorkflowEventResponseStatusInProgress WorkflowEventResponseStatus = "In Progress"
	WorkflowEventResponseStatusCompleted  WorkflowEventResponseStatus = "Completed"
)

func (WorkflowEventResponseStatus) IsKnown added in v0.12.0

func (r WorkflowEventResponseStatus) IsKnown() bool

Directories

Path Synopsis
packages

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL