LedgeKitDocs
iOS SDK
Developer documentation

Capture inputs and prompt templates

Save typed application arguments separately from the native model request.

Use one optional recording: argument for application input, prompt template, and output references. Input and template accept normal Encodable & Sendable values.

struct SummaryInput: Codable, Sendable { let text: String }
let input = SummaryInput(text: text)
let response = try await session.respond(
    to: "Summarize: \(input.text)",
    recording: .init(
        input: input,
        promptTemplate: [
            "instructions": "Summarize the text in one sentence.",
            "prompt": "Summarize: {{text}}"
        ]
    )
)

Configure the native session with the actual instructions. Your code renders the prompt; LedgeKit saves the template as supplied and does not interpret placeholders.

Recorded fieldMeaning
inputOriginal application arguments, before prompt rendering.
modelInputNative input sent to the model, including available history.
modelOutputNative response, before application postprocessing.
providerCaptureFull provider snapshot and call boundaries.
promptTemplateOptional unrendered template supplied by the application.
outputReferencesOptional display annotations for returned identifiers.

Application input and template are saved when the span starts, including when the model later fails or is interrupted. Values are scoped to that call; subsequent calls do not inherit them. Encoding failures emit a diagnostic and preserve an explicit capture-error marker without preventing model execution.

Workflow input

try await client.withTrace("summarize_and_review", version: 1, input: input) { trace in
    // Each model call supplies its own recording.input when needed.
}

Trace input belongs to the whole workflow. Span input belongs to one agent call. Either can be saved to a dataset. Include the arguments needed to execute current application code again, rather than inferring them from a prompt.

Use LedgeJSONValue.null for explicit JSON null; omitted optional input means nothing was captured. Captured values count toward the 4 MiB trace limit.

On this page