<!--
{
  "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/Instructions",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Foundation Models"
    ],
    "preciseIdentifier" : "s:16FoundationModels12InstructionsV"
  },
  "title" : "Instructions"
}
-->

# Instructions

Details you provide that define the model’s intended behavior on prompts.

```
struct Instructions
```

## Overview

You typically provide instructions to define the role and behavior of
the model. In the code below, the instructions specify that the model replies
with topics rather than, for example, a recipe:

```swift
let instructions = """
    Suggest related topics. Keep them concise (three to seven words) and make sure they \
    build naturally from the person's topic.
    """

let session = LanguageModelSession(instructions: instructions)

let prompt = "Making homemade bread"
let response = try await session.respond(to: prompt)
```

Don’t include untrusted content in instructions: the model is typically trained to obey
instructions over any commands it receives in prompts. For more on how instructions
impact generation quality and safety, see [Improving the safety of generative model output](/documentation/FoundationModels/improving-the-safety-of-generative-model-output).

All input to the model contributes tokens to the context window of the
[`LanguageModelSession`](/documentation/FoundationModels/LanguageModelSession) — including the [`Instructions`](/documentation/FoundationModels/Instructions), [`Prompt`](/documentation/FoundationModels/Prompt), [`Tool`](/documentation/FoundationModels/Tool),
and [`Generable`](/documentation/FoundationModels/Generable) types, and the model’s responses. If your session exceeds the
available context size, it throws  [`LanguageModelError.contextSizeExceeded(_:)`](/documentation/FoundationModels/LanguageModelError/contextSizeExceeded(_:)).

Instructions can consume a lot of tokens that contribute to the context window
size. To reduce your instruction size:

- Write shorter instructions to save tokens.
- Provide only the information necessary to perform the task.
- Use concise and imperative language instead of indirect or jargon that the model might misinterpret.
- Aim for one to three paragraphs instead of including a significant amount of background information,
  policy, or extra content.

For more information on managing the context window size, see [Managing the context window](/documentation/FoundationModels/managing-the-context-window).

## Topics

### Creating instructions

[`init(_:)`](/documentation/FoundationModels/Instructions/init(_:))

[`InstructionsBuilder`](/documentation/FoundationModels/InstructionsBuilder)

A type that represents an instructions builder.

[`InstructionsRepresentable`](/documentation/FoundationModels/InstructionsRepresentable)

A type that can be represented as instructions.



---

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)