picoflow.io

Lesson 7: FavoritesStep — Structured Output Loop


Prompt + Schema Pair

FavoritesStep loads prompt and JSON schema from disk:

const PROMPT = Prompt.file('prompt/favorites.md');
const SCHEMA = Prompt.file('prompt/favorites.json');

public getPrompt(): string {
  return Prompt.replace(PROMPT, { QUESTION_SCHEMA: SCHEMA });
}

Schema requires:

{
  "favoriteColor": { "enum": ["red", "blue", "white"] },
  "favoriteMovie": { "type": "string" },
  "favoriteSeason": { "enum": ["spring", "summer", "autumn", "winter"] }
}

Response Handling

public onResponse(llmText: string): string | StepClassType {
  const json = StringUtil.parseJson(llmText);
  if (json) {
    this.saveState({ favorites: json });
    return NameStep;
  }
  return llmText;
}
  • Strict parse; failure keeps the step active.
  • Success stores structured data and loops to NameStep for follow-up collection.
Tip

Pair prompt + schema files to keep contracts explicit and auditable.

Next: NameStep with runtime context injection and an InContext sub-agent.