---
title: Instructions
framework: foundationmodels
role: symbol
role_heading: Structure
path: foundationmodels/instructions
---

# Instructions

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

## Declaration

```swift
struct Instructions
```

## Mentioned in

Composing dynamic sessions with instructions and profiles Generating content and performing tasks with Foundation Models Improving the safety of generative model output Prompting an on-device foundation model Supporting languages and locales with Foundation Models

## Overview

Overview Instructions are typically provided by you 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: 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) Apple trains the model to obey instructions over any commands it receives in prompts, so don’t include untrusted content in instructions. For more on how instructions impact generation quality and safety, see Improving the safety of generative model output. All input to the model contributes tokens to the context window of the LanguageModelSession — including the Instructions, Prompt, Tool, and Generable types, and the model’s responses. If your session exceeds the available context size, it throws  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.

## Topics

### Creating instructions

- [init(_:)](foundationmodels/instructions/init(_:).md)
- [InstructionsBuilder](foundationmodels/instructionsbuilder.md)
- [InstructionsRepresentable](foundationmodels/instructionsrepresentable.md)

## Relationships

### Conforms To

- [Copyable](swift/copyable.md)
- [DynamicInstructions](foundationmodels/dynamicinstructions.md)
- [Escapable](swift/escapable.md)
- [InstructionsRepresentable](foundationmodels/instructionsrepresentable.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Sessions and prompts

- [Prompting an on-device foundation model](foundationmodels/prompting-an-on-device-foundation-model.md)
- [Managing the context window](foundationmodels/managing-the-context-window.md)
- [Updating prompts for new model versions](foundationmodels/updating-prompts-for-new-model-versions.md)
- [LanguageModelSession](foundationmodels/languagemodelsession.md)
- [Prompt](foundationmodels/prompt.md)
- [Transcript](foundationmodels/transcript.md)
- [TranscriptErrorHandlingPolicy](foundationmodels/transcripterrorhandlingpolicy.md)
- [GenerationOptions](foundationmodels/generationoptions.md)
- [ContextOptions](foundationmodels/contextoptions.md)
