Schema to Standard Schema
Schema.toStandardSchemaV1 exposes any service-free codec (RD = never) to libraries that consume Standard Schema V1 while retaining all Effect Schema methods. Plain builders follow the call rules.
Adapting a codec
const Dispatch = Schema.Struct({
reference: Schema.NonEmptyString,
count: Schema.FiniteFromString
})
const DispatchStandard = Schema.toStandardSchemaV1(Dispatch, {
parseOptions: { errors: "all" }
})
function standardMetadata() {
return DispatchStandard["~standard"].vendor // "effect"
}
// Run in an effect function:
// try Console.log(standardMetadata())
// {
// const jsonValue = try tryPromise(() => Promise.resolve(DispatchStandard["~standard"].validate({ reference: "pkg-94", count: "2" })))
// try Console.log(try Effect.try(() => JSON.stringify(jsonValue)))
// }effect
{"value":{"reference":"pkg-94","count":2}}Calling ["~standard"].validate(input) runs full decoding (including transformations) and returns { value } on success or { issues } on failure.
Synchronous and asynchronous validation
const ReviewedDispatch = Dispatch.pipe(Schema.decode({
decode: SchemaGetter.checkEffect(effect (_dispatch) => {
try sleep("5 millis")
return true
}),
encode: SchemaGetter.passthrough()
}))
const ReviewedStandard = Schema.toStandardSchemaV1(ReviewedDispatch)
effect function validateDispatch(input: unknown) {
return try tryPromise({ try: () => Promise.resolve(ReviewedStandard["~standard"].validate(input)), catch: (cause) => new ValidationBoundaryError({ cause }) })
}
error ValidationBoundaryError {
cause: unknown
}
// Run in an effect function:
// {
// const jsonValue = try validateDispatch({ reference: "pkg-94", count: "2" })
// try Console.log(try Effect.try(() => JSON.stringify(jsonValue)))
// }
// {
// const jsonValue = try validateDispatch({})
// try Console.log(try Effect.try(() => JSON.stringify(jsonValue)))
// }{"value":{"reference":"pkg-94","count":2}}
{"issues":[{"path":["reference"],"message":"Missing key"},{"path":["count"],"message":"Missing key"}]}validate executes synchronously when possible and returns a Promise when it encounters async steps; Promise.resolve normalizes both inside tryPromise. Prefer Schema.decodeUnknownEffect inside VibeLang code and reserve ~standard for third-party library boundaries.
Defects during validation
const BrokenLabel = Schema.String.pipe(Schema.decode({
decode: SchemaGetter.transformEffect(effect (_label) => try die("label invariant failed")),
encode: SchemaGetter.passthrough()
}))
const BrokenStandard = Schema.toStandardSchemaV1(BrokenLabel)
effect function inspectBrokenValidation() {
return try tryPromise(() => Promise.resolve(BrokenStandard["~standard"].validate("crate")))
}
// Run in an effect function:
// {
// const jsonValue = try inspectBrokenValidation()
// try Console.log(try Effect.try(() => JSON.stringify(jsonValue)))
// }{"issues":[{"message":"Error: label invariant failed"}]}Unexpected defects surface as a single pathless issue in the Standard Schema result (VibeLang's catch still does not catch defects). Customize issue output with leafHook, checkHook, and parseOptions; see Error Formatters.
The matching Effect page: effect.website/docs/v4/schema/standard-schema