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.