Documentation
¶
Overview ¶
Package wire implements the command-safety classifier's strict, versioned JSON codecs for the model's input and output payloads: MarshalInput (input.go) projects a validated gate.PermissionReviewSubject into the bounded, versioned JSON the model sees as evidence, and DecodeOutput (output.go) strictly decodes and validates the model's structured-output verdict back into a gate.PermissionAssessment. Both directions follow the same strict decode discipline Harness's own pkg/gate uses for its wire codecs (see strict.go): no unknown or duplicate JSON field, no JSON null masquerading as an omitted field, and no trailing content.
Index ¶
- Constants
- func DecodeOutput(subject gate.PermissionReviewSubject, raw json.RawMessage) (gate.PermissionAssessment, error)
- func MarshalInput(subject gate.PermissionReviewSubject) (json.RawMessage, error)
- func OutputSchema() inference.OutputSchema
- type InputValidationError
- type InputValidationField
- type InputValidationReason
- type OutputValidationError
- type OutputValidationField
- type OutputValidationReason
Constants ¶
const ( // InputWireVersion is the literal version tag stamped on every marshaled // input payload. InputWireVersion = "command_safety_input.v1" // InputRevision independently versions this wire's shape, per design // §19.2. InputRevision = "command-safety-input/v1" // MaxInputWireBytes bounds the marshaled input payload. MaxInputWireBytes = 1 << 20 )
const ( // OutputSchemaName is the model-facing structured-output schema name // handed to inference.OutputSchema. OutputSchemaName = "command_safety_assessment" // OutputRevision independently versions this wire's shape and strict // decode discipline, per design §19.2 ("prompt, policy, schema, wire, // and corpus revisions are independently explicit and included in // classifier identity"). OutputRevision = "command-safety-output/v1" // MaxOutputWireBytes bounds the raw structured-output JSON before it is // parsed, independent of any hustle-level payload limit. MaxOutputWireBytes = 64 * 1024 )
Variables ¶
This section is empty.
Functions ¶
func DecodeOutput ¶
func DecodeOutput(subject gate.PermissionReviewSubject, raw json.RawMessage) (gate.PermissionAssessment, error)
DecodeOutput strictly decodes and validates one model structured-output payload against subject, and returns the resulting PermissionAssessment. Unknown fields, duplicate JSON keys, JSON null in any required position, trailing JSON content, an oversized payload, an oversized or (for non-low risk) empty rationale, an unknown or duplicate category, an unrecognized enum value, and a basis that does not exactly match subject are all rejected. The returned assessment's Basis is always subject.Basis verbatim — the model's echoed basis is used only to confirm consistency, never to populate the trusted result.
func MarshalInput ¶
func MarshalInput(subject gate.PermissionReviewSubject) (json.RawMessage, error)
MarshalInput projects a validated PermissionReviewSubject into the versioned, bounded JSON view the model sees as this classifier's evidence. subject.Context's entries are carried verbatim: the prompt (not this codec) is responsible for labeling them as untrusted data.
func OutputSchema ¶
func OutputSchema() inference.OutputSchema
OutputSchema returns the provider-neutral structured-output policy handed to the model. It returns a fresh clone on every call so callers cannot mutate shared state.
Types ¶
type InputValidationError ¶
type InputValidationError struct {
Field InputValidationField
Reason InputValidationReason
}
InputValidationError reports a subject that cannot be marshaled into the model input wire. It deliberately carries no subject content.
func (*InputValidationError) Error ¶
func (e *InputValidationError) Error() string
type InputValidationField ¶
type InputValidationField string
InputValidationField identifies the bounded part of a subject that failed input marshaling.
const ( InputFieldSubject InputValidationField = "subject" InputFieldWire InputValidationField = "wire" )
type InputValidationReason ¶
type InputValidationReason string
InputValidationReason classifies an input marshaling failure.
const ( InputReasonRequired InputValidationReason = "required" InputReasonInvalid InputValidationReason = "invalid" InputReasonMismatch InputValidationReason = "mismatch" InputReasonOutOfBounds InputValidationReason = "out_of_bounds" )
type OutputValidationError ¶
type OutputValidationError struct {
Field OutputValidationField
Reason OutputValidationReason
}
OutputValidationError reports a rejected model structured-output payload. It deliberately carries no rejected value — in particular never the model's rationale text — so untrusted or oversized model output can never leak through an error message, log line, or audit record.
func (*OutputValidationError) Error ¶
func (e *OutputValidationError) Error() string
func (*OutputValidationError) Retryable ¶
func (e *OutputValidationError) Retryable() bool
Retryable reports whether this output-validation failure is a pure syntax/shape signal, safe for a caller to treat as hustle.NewRecoverableTerminalValidationError() under hustle.RetryPolicyClassifiedOnce (design §12.6). Every DecodeOutput failure is a shape problem — duplicate/unknown/missing/null wire fields, an oversized or non-UTF-8 payload, or a malformed/non-canonical enum string — EXCEPT a basis mismatch, which is a semantic identity check (the model echoed back a basis that does not match the trusted subject) and design §12.6 explicitly excludes: "A basis mismatch ... must not use it."
type OutputValidationField ¶
type OutputValidationField string
OutputValidationField identifies the bounded part of a model's structured output that failed validation.
const ( OutputFieldWire OutputValidationField = "wire" OutputFieldBasis OutputValidationField = "basis" OutputFieldRisk OutputValidationField = "risk" OutputFieldAuthorization OutputValidationField = "authorization" OutputFieldCategories OutputValidationField = "categories" OutputFieldRecommendation OutputValidationField = "recommendation" OutputFieldRationale OutputValidationField = "rationale" )
type OutputValidationReason ¶
type OutputValidationReason string
OutputValidationReason classifies an output validation failure.
const ( OutputReasonRequired OutputValidationReason = "required" OutputReasonInvalid OutputValidationReason = "invalid" OutputReasonUnsupported OutputValidationReason = "unsupported" OutputReasonOutOfBounds OutputValidationReason = "out_of_bounds" OutputReasonMismatch OutputValidationReason = "mismatch" )