We are building an Educational Text Analyzer that ingests raw curriculum passages and returns structured pedagogical metadata, including reading level, key concepts, prerequisites, and comprehension questions. This gives instructional designers and ed-tech developers a programmatic way to audit and enrich content at scale. Because Oxlo.ai charges one flat rate per request rather than per token, you can feed it full textbook chapters without watching costs climb with every extra paragraph.
What you'll need
- Python 3.10 or newer
- The OpenAI SDK:
pip install openai - An Oxlo.ai API key from https://portal.oxlo.ai
Step 1: Initialize the Oxlo.ai client
I start by importing the OpenAI SDK and pointing it at Oxlo.ai's base URL. This is a drop-in replacement, so the code looks identical to what you might write for any OpenAI-compatible provider.
from openai import OpenAI
import json
client = OpenAI(
base_url="https://api.oxlo.ai/v1",
api_key="YOUR_OXLO_API_KEY" # Replace with your key from https://portal.oxlo.ai
)
Step 2: Define the system prompt
The system prompt is where I encode the pedagogy rules. I tell the model to behave as an instructional design assistant and to return only valid JSON with specific fields. Keeping this in a dedicated constant makes it easy to tweak later without touching the request logic.
SYSTEM_PROMPT = """You are an instructional design assistant. Analyze the provided educational text and return a JSON object with exactly these keys:
- reading_level: one of "elementary", "middle_school", "high_school", "undergraduate", or "graduate"
- key_concepts: list of the 5 most important concepts covered
- prerequisites: list of 3 to 5 concepts a student should already understand
- common_misconceptions: list of 2 to 3 likely student misunderstandings
- comprehension_questions: list of 3 question-and-answer objects, each with "question" and "answer" strings
Be concise. Do not include markdown formatting inside the JSON."""
Step 3: Build the analyzer function
I wrap the API call in a small function so I can reuse it across different passages. I use Oxlo.ai's JSON mode by setting response_format to {"type": "json_object"}, which forces the model to emit valid JSON. I use the Llama 3.3 70B model here because it handles general-purpose instruction following reliably, but you could swap in Qwen 3 32B for multilingual curricula or Kimi K2.6 for heavier reasoning.
def analyze_educational_text(passage: str) -> dict:
response = client.chat.completions.create(
model="llama-3.3-70b",
messages=[
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": passage},
],
response_format={"type": "json_object"},
temperature=0.2,
)
content = response.choices[0].message.content
return json.loads(content)
Step 4: Prepare a sample passage
For this demo I use a short excerpt about photosynthesis. In production you might read this from a PDF or CMS, but a hardcoded string is enough to verify the pipeline.
SAMPLE_TEXT = """Photosynthesis is the process by which green plants and some other organisms use sunlight to synthesize foods with the help of chlorophyll pigments. The process generally occurs in the leaves of plants, where chloroplasts convert light energy into chemical energy. During photosynthesis, plants take in carbon dioxide from the air and water from the soil. Using light energy, they convert these raw materials into glucose, a simple sugar that provides energy and building materials for the plant. Oxygen is released as a byproduct. The overall chemical equation for photosynthesis is 6CO2 + 6H2O + light energy -> C6H12O6 + 6O2."""
Run it
Now I call the analyzer on the sample text and print the formatted results. This is the exact script I run to validate the output before wiring it into a larger content management pipeline.
if __name__ == "__main__":
result = analyze_educational_text(SAMPLE_TEXT)
print(json.dumps(result, indent=2))
When I run this, the output looks like the following block. Your exact JSON may vary slightly depending on model sampling, but the structure will always match the schema defined in the system prompt because of JSON mode.
{
"reading_level": "middle_school",
"key_concepts": [
"Photosynthesis",
"Chlorophyll",
"Chloroplasts",
"Glucose production",
"Oxygen byproduct"
],
"prerequisites": [
"Basic understanding of plants and leaves",
"Knowledge of chemical equations",
"Familiarity with energy concepts",
"Understanding of carbon dioxide and water"
],
"common_misconceptions": [
"Plants get most of their mass from soil rather than air",
"Photosynthesis only happens during the day in all plants",
"Oxygen is the main product plants produce for themselves"
],
"comprehension_questions": [
{
"question": "What are the two main raw materials needed for photosynthesis?",
"answer": "Carbon dioxide and water."
},
{
"question": "Where in the plant does photosynthesis primarily take place?",
"answer": "In the chloroplasts within the leaves."
},
{
"question": "What is the simple sugar produced during photosynthesis?",
"answer": "Glucose."
}
]
}
Wrap-up
This analyzer is already useful for tagging content in a learning management system, but two concrete extensions make it production-ready. First, batch the function across an entire textbook by feeding each section through the Oxlo.ai API in a loop, which stays cheap on their per-request pricing even when individual chapters run long. Second, store the resulting JSON in a vector database alongside the original text so you can later query for content gaps by searching for missing prerequisites. Oxlo.ai's full OpenAI SDK compatibility means you can drop this logic into existing pipelines without rewriting your HTTP client.
Top comments (0)