Building a Safe AI Story Generator for Kids
A worked example showing how pepiko.ai's APIs fit together inside an AI story generator for kids, from a typed story idea to a finished, age-appropriate story.
A note before you read this: this is a worked example we built ourselves to show how the pieces fit together — it isn't a paid endorsement or a named customer's measured results. If you're already building with pepiko.ai and would like your own story featured here instead, get in touch.
The scenario
A small team is building an app where kids aged 6-11 type a story idea — "a dragon who's scared of the dark," "my dog becomes a superhero" — and get back an original, illustrated story generated on the spot. Unlike a homework-help chatbot answering structured questions, this is open-ended creative content in both directions: the prompt a child types can be anything, and the story the model writes back is different every single time. A simple keyword filter can't tell the difference between a scary-but-ordinary fairy-tale trope (a wolf, a monster under the bed) and content that's genuinely inappropriate for the age group — and because the output is freshly generated, not pre-written, it has to be checked every time too, not just the prompt that triggered it. The team wired in pepiko.ai's Prompt Classifier, Moderation API, Child Safety Classification, and Policy Route APIs instead.
Wiring the safety pipeline together
Every story idea a child types goes through this pipeline before a story is generated, and the finished story goes through it again before it's shown or read aloud.
1. Classify the prompt's intent before generating
The Prompt Classifier looks at the raw story idea first and buckets it by intent, so the app knows whether to go straight to story generation or take a closer look first.
POST /v1/prompt/classify
{
"text": "write a story about a dragon who is scared of the dark",
"user_age": "6-9",
"context": { "platform": "kids_story_generator" }
}
Response
{
"intent": "creative_writing_request",
"safety_category": "none",
"policy_bucket": "standard_response",
"confidence": 0.98
}
2. Screen the generated story before it's shown
Because the model writes something new every time, the Moderation API screens the finished story text itself — not just the prompt that produced it — for age-inappropriate content before it ever reaches the child's screen.
POST /v1/moderation/classify
{
"text": "[generated story text]",
"user_age": "6-9",
"context": { "platform": "kids_story_generator", "content_type": "generated_story" }
}
Response
{
"category": "mild_peril",
"risk_level": "low",
"policy_bucket": "standard_response",
"confidence": 0.94
}
3. Catch risk signals hiding inside a "story"
Kids sometimes use the fiction framing to describe something real that's happening to them. Child Safety Classification is trained to catch that distinction — a genuine risk signal wrapped in creative language — that a generic moderation pass would likely read as ordinary story content.
POST /v1/child-safety/classify
{
"text": "write a story about a girl whose classmates want her to disappear",
"user_age": "6-9",
"context": { "platform": "kids_story_generator" }
}
Response
{
"risk_category": "possible_bullying_distress",
"risk_level": "elevated",
"recommended_action": "escalate_supportive_response",
"confidence": 0.89
}
4. Decide how the product responds
Policy Route takes the outputs from the calls above and turns them into an actual decision: generate the story normally, regenerate it with a gentler direction, or pause and show a supportive check-in instead, flagged for human review.
POST /v1/policy/route
{
"risk_category": "possible_bullying_distress",
"risk_level": "elevated",
"user_age": "6-9"
}
Response
{
"action": "escalate_supportive_response",
"response_template": "supportive_checkin_v2",
"notify_human_review": true
}
What this changes in practice
The vast majority of story ideas — dragons, superhero dogs, magic treehouses — pass through classification in well under 250ms and go straight to generation, completely unaffected. The difference shows up in the small percentage of prompts and generated stories that actually need a second look: instead of either blocking every idea that mentions something scary (over-blocking harmless, ordinary creative requests) or letting anything through because "it's just a story" (a generic filter missing the real signal underneath), the product screens both the prompt and the finished story, and routes only the genuinely elevated cases to a supportive response — while every other story still ships instantly.
A protected interface layer for creative kids' content
Generative products for kids carry a different shape of risk than a chatbot answering questions: the app isn't just responsible for what a child types, it's also responsible for what the AI writes back, every time, with no two stories the same. That's exactly the gap a protected interface layer is built to close — classifying both sides of the exchange, the prompt and the generated content, in real time, so safety isn't something bolted on after a story ships. It's built into the pipeline that generates it.
Try it yourself
The full request/response schemas for all four endpoints shown above are in the API docs, and the free tier is enough to wire up this exact pipeline end to end.
Back to case studies →
