One Logo Pool Ball
FoundationModels · IOS API REFERENCE

LanguageModelSession.GenerationError.Refusal

struct · iOS 26.0+ · SDK 27.1

struct Refusal

A refusal produced by a language model. Refusal errors indicate that the model chose not to respond to a prompt. To make the model explain why it refused, catch the refusal error and access one of its explanation properties. ```swift do { let session = LanguageModelSession() let response = try session.respond(to: "...") } catch error as LanguageModelSession.GenerationError.refusal(let refusal, _) { let message = try await refusal.explanation print(message) } catch { print("Something went wrong: \(error)") } ```

Members (3)

get · iOS 26.0+

explanation

TypeScript
get explanation(): Promise<LanguageModelSession_Response<string>>
Swift declaration
nonisolated(nonsending) var explanation: LanguageModelSession.Response<String> { get async throws }

An explanation for why the model refused to respond.

get · iOS 26.0+

explanationStream

TypeScript
get explanationStream(): LanguageModelSession_ResponseStream<string>
Swift declaration
var explanationStream: LanguageModelSession.ResponseStream<String> { get }

A stream containing an explanation about why the model refused to respond.

init · iOS 26.0+

init

TypeScript
static init(transcriptEntries: Array<Transcript_Entry>): LanguageModelSession_GenerationError_Refusal
Swift declaration
init(transcriptEntries: [Transcript.Entry])

Skipped declarations

No declarations were skipped in this snapshot.

All FoundationModels types →