PrismPromptChain class

Runs a sequence of prompts where each step's output feeds the next.

Steps run in order. Each step's prompt has its {{…}} placeholders replaced with values from the context, which starts with the caller's input and accumulates each step's output. A step that throws aborts the chain and re-throws.

final chain = PrismPromptChain([
  PrismChainStep<Map<String, Object?>>(
    prompt: 'Extract the sentiment from: {{input.text}}',
    outputKey: 'sentiment',
    parse: (r) => PrismStructuredOutput.extractMap(r) ?? {},
  ),
  PrismChainStep<String>(
    prompt: 'Given the sentiment {{sentiment.sentiment}}, write a reply.',
    outputKey: 'reply',
    parse: (r) => r,
  ),
]);

final result = await chain.run(
  client,
  {'text': 'This product is amazing!'},
  model: 'gpt-4o-mini',
);
print(result['reply']);

Constructors

PrismPromptChain(List<PrismChainStep<Object>> steps, {String? systemPrompt})
Creates a prompt chain.
const

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
steps → List<PrismChainStep<Object>>
The steps, run in order.
final
systemPrompt → String?
Optional system message sent with every step.
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
run(AiStreamClient client, Map<String, Object?> input, {required String model, double? temperature, int? maxTokens}) → Future<Map<String, Object?>>
Runs all steps and returns the accumulated context.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited