One Logo Pool Ball
FoundationModels · IOS API REFERENCE

Prompt

struct · iOS 26.0+ · SDK 27.1

struct Prompt

A prompt from a person to the model. Prompts can contain content written by you, an outside source, or input directly from people using your app. You can initialize a `Prompt` from a string literal: ```swift let prompt = Prompt("What are miniature schnauzers known for?") ``` Use ``PromptBuilder`` to dynamically control the prompt's content based on your app's state. The code below shows if the Boolean is `true`, the prompt includes a second line of text: ```swift let responseShouldRhyme = true let prompt = Prompt { "Answer the following question: Do Siberian Huskies love cold weather?" if responseShouldRhyme { "Your response MUST rhyme!" } } ``` If your prompt includes input from people, consider wrapping the input in a string template with your own prompt to better steer the model's response. For more information on handling inputs in your prompts, see <doc:improving-the-safety-of-generative-model-output>. Prompting the same session eventually leads to exceeding the context window size. You can recover from this error by removing entries from the transcript and trying again. For more information on managing the context window size, see <doc:managing-the-context-window>.

Members (3)

get · iOS 26.0+

promptRepresentation

TypeScript
get promptRepresentation(): Prompt
Swift declaration
var promptRepresentation: Prompt { get }

An instance that represents a prompt.

init · iOS 26.0+

init

TypeScript
static init(content: (() => Prompt)): Prompt
Swift declaration
init(@PromptBuilder _ content: () throws -> Prompt) rethrows
init · iOS 26.0+

init

TypeScript
static init35397(content: SDKHandle): Prompt
Swift declaration
init(_ content: some PromptRepresentable)

Creates an instance with the content you specify.

Skipped declarations

No declarations were skipped in this snapshot.

All FoundationModels types →