---
title: "onToolOutput(perform:)"
framework: foundationmodels
role: symbol
role_heading: Instance Method
path: "foundationmodels/languagemodelsession/dynamicprofile/ontooloutput(perform:)"
---

# onToolOutput(perform:)

Runs an action whenever a tool call output is received within this dynamic profile.

## Declaration

```swift
func onToolOutput(perform action: nonisolated(nonsending) sending @escaping () async throws -> Void) -> some LanguageModelSession.DynamicProfile

```

## Mentioned in

Composing dynamic sessions with instructions and profiles

## Discussion

Discussion When the onToolOutput closure throws an error, the caller’s respond or response will propagate that error. Use this to track or log tool output within a dynamic profile: struct MyDynamicProfile: LanguageModelSession.DynamicProfile {   var body: some LanguageModelSession.DynamicProfile {     Profile {       Instructions("You are a helpful assistant.")       SomeTool()     }     .onToolOutput {       toolOutputCount += 1     }   } }

## See Also

### Observing life cycle modifiers

- [onActivate(perform:)](foundationmodels/languagemodelsession/dynamicprofile/onactivate(perform:).md)
- [onDeactivate(perform:)](foundationmodels/languagemodelsession/dynamicprofile/ondeactivate(perform:).md)
- [onPrompt(perform:)](foundationmodels/languagemodelsession/dynamicprofile/onprompt(perform:).md)
- [onResponse(perform:)](foundationmodels/languagemodelsession/dynamicprofile/onresponse(perform:).md)
- [onToolCall(perform:)](foundationmodels/languagemodelsession/dynamicprofile/ontoolcall(perform:).md)
