<!--
{
  "availability" : [
    "iOS: 26.0.0 -",
    "iPadOS: 26.0.0 -",
    "macCatalyst: 26.0.0 -",
    "macOS: 26.0.0 -",
    "visionOS: 26.0.0 -",
    "watchOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "FoundationModels",
  "identifier" : "/documentation/FoundationModels/LanguageModelSession/logFeedbackAttachment(sentiment:issues:desiredOutput:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation Models",
      "FoundationModels"
    ],
    "preciseIdentifier" : "s:16FoundationModels20LanguageModelSessionC21logFeedbackAttachment9sentiment6issues13desiredOutput0A04DataVAA0cdG0V9SentimentOSg_SayAL5IssueVGAA10TranscriptV5EntryOSgtF"
  },
  "title" : "logFeedbackAttachment(sentiment:issues:desiredOutput:)"
}
-->

# logFeedbackAttachment(sentiment:issues:desiredOutput:)

Logs and serializes a feedback attachment that can be submitted to Apple.

```
@discardableResult final func logFeedbackAttachment(sentiment: LanguageModelFeedback.Sentiment?, issues: [LanguageModelFeedback.Issue] = [], desiredOutput: Transcript.Entry? = nil) -> Data
```

## Parameters

`sentiment`

An optional sentiment rating about the model’s output (positive, negative, or neutral).

`issues`

An array of specific issues identified with the model’s response. Defaults to an empty array.

`desiredOutput`

An optional transcript entry showing what the desired output should have been.

## Return Value

A `Data` object containing the JSON-encoded feedback attachment that can be submitted to Feedback Assistant.

## Discussion

This method creates a structured feedback attachment containing the session’s transcript
and any provided feedback information. The attachment can be saved to a file and submitted
to Apple using [Feedback Assistant](https://feedbackassistant.apple.com).

If an error occurred during a previous response, any rejected entries that were rolled
back from the transcript are included in the feedback data.

```swift
let session = LanguageModelSession()
let response = try await session.respond(to: "What is the capital of France?")

// Create feedback for a helpful response
let feedbackData = session.logFeedbackAttachment(sentiment: .positive)

// Or create feedback for a problematic response
let feedbackData = session.logFeedbackAttachment(
    sentiment: .negative,
    issues: [
        LanguageModelFeedback.Issue(
            category: .incorrect,
            explanation: "The model provided outdated information"
        )
    ],
    desiredOutput: Transcript.Entry.response(...)
)
```

If your `desiredOutput` is a string, use [`Transcript.Entry.response(_:)`](/documentation/FoundationModels/Transcript/Entry/response(_:)) to turn your desired output into a
[`Transcript`](/documentation/FoundationModels/Transcript) entry:

```swift
let text = Transcript.TextSegment(content: "The capital of France is Paris.")
let segment = Transcript.Segment.text(text)
let response = Transcript.Response(segments: [segment])
let entry = Transcript.Entry.response(response)
```

If your `desiredOutput` is a [`Generable`](/documentation/FoundationModels/Generable) type, turning that into a [`Transcript`](/documentation/FoundationModels/Transcript) entry is slightly different:

```swift
let customType = MyCustomType(...) // A generable type.
let structure = Transcript.StructuredSegment(schemaName: String(describing: Foo.self), content: customType.generatedContent)
let segment = Transcript.Segment.structure(structure)
let response = Transcript.Response(segments: [segment])
let entry = Transcript.Entry.response(response)
```

Finally, if you’d like to submit the feedback to Apple, write your feedback to a `.json` file and include the file as an
attachment to [Feedback Assistant](https://feedbackassistant.apple.com). You can include one or many
feedback attachment in the same file:

```swift
let allFeedback = feedbackData + feedbackData2 + feedbackData3
let url = URL(fileURLWithPath: "path/to/save/feedback.json")
try allFeedback.write(to: url)
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)