Skip to main content
This recipe builds a question-answering bot with SeekrFlow that pairs every answer with a confidence score, a signal for how much to trust the reply. It calls a chat model directly through SeekrFlow’s serverless inference and parses the rating out of the response, with no extra frameworks.

What you’ll build

A Q&A bot that:
  1. Answers questions about any topic.
  2. Returns a confidence score with each answer.
  3. Flags low-confidence answers for follow-up.

Prerequisites

  • A SeekrFlow API key, set as the SEEKR_API_KEY environment variable
  • Python 3.8 or later
  • The SeekrFlow SDK: pip install seekrai
Each question you ask is billed as serverless inference, charged by the token.

Build it

1

Set up the client

Create qa_bot.py with the imports, configuration, and client.
2

Write the prompt

Write a prompt that asks the model for an answer followed by a confidence rating on its own line. Parsing depends on that Confidence: marker. Keep it in the instructions.
3

Parse the response

Write a helper that splits the answer from the confidence rating and its explanation.
4

Ask a question

Wrap the model call and parser in a function that prints the answer, its confidence, and a follow-up hint when confidence is low. A low temperature keeps answers more deterministic.
5

Ask a few questions

Run a few questions of varying difficulty to see the confidence score change.
6

Run the script

Run the finished script:
Easy, well-known questions should come back with high confidence; obscure ones should score lower and trigger the follow-up hint.

Next steps

  • Keep context across turns. Hold a running messages list and include prior turns in each call to answer follow-up questions in context.
  • Tune the threshold. Adjust which confidence scores trigger the follow-up hint to match how cautious you want the bot to be.
  • Ground the answers. Combine this with the New hire onboarding agent with citations so answers come from your own documents.
Last modified on July 16, 2026