MCPcopy Create free account
hub / github.com/Effect-TS/effect / InvalidOutputError

Class InvalidOutputError

packages/effect/src/unstable/ai/AiError.ts:695–746  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

693 * @since 4.0.0
694 */
695export class InvalidOutputError extends Schema.Error<InvalidOutputError>(
696 "effect/ai/AiError/InvalidOutputError"
697)({
698 _tag: Schema.tag("InvalidOutputError"),
699 description: Schema.String,
700 metadata: providerMetadataWithDefaults<InvalidOutputErrorMetadata>(),
701 usage: Schema.optional(UsageInfo)
702}) {
703 /**
704 * Marks `InvalidOutputError` as a semantic AI error reason for runtime guards.
705 *
706 * @since 4.0.0
707 */
708 readonly [ReasonTypeId] = ReasonTypeId
709
710 /**
711 * Invalid output errors are retryable since LLM outputs are non-deterministic.
712 *
713 * @since 4.0.0
714 */
715 get isRetryable(): boolean {
716 return true
717 }
718
719 /**
720 * Creates an InvalidOutputError from a Schema error.
721 *
722 * **Example** (Creating an invalid output error from a schema error)
723 *
724 * ```ts import.meta.vitest
725 * import { Effect, Schema } from "effect"
726 * import { AiError } from "effect/unstable/ai"
727 *
728 * const schemaError = await Effect.runPromise(
729 * Schema.decodeUnknownEffect(Schema.Number)("not a number").pipe(Effect.flip)
730 * )
731 * const parseError = AiError.InvalidOutputError.fromSchemaError(schemaError)
732 * parseError.description // => "Expected number"
733 * ```
734 *
735 * @since 4.0.0
736 */
737 static fromSchemaError(error: Schema.SchemaError): InvalidOutputError {
738 return new InvalidOutputError({
739 description: error.message
740 })
741 }
742
743 override get message(): string {
744 return `Invalid output: ${this.description}`
745 }
746}
747
748/**
749 * Error indicating the LLM generated text that does not conform to the

Callers

nothing calls this directly

Calls 2

tagMethod · 0.65

Tested by

no test coverage detected