Skip to main content
Seb Duerr
January 23, 2026
Open in Github
This cookbook demonstrates how to build hyper-personalized web pages that adapt to each visitor in real-time:
  • Preferred colors - Pages render in the user’s chosen color scheme
  • Tone - Content adjusts to formal, casual, or friendly language
  • Products - Featured items match user interests and demographics
  • Language - Full multilingual support (English, Spanish, German)
Cerebras’ ultra-fast inference makes this possible at page-load speed—personalization that would take seconds with other providers happens in milliseconds.

What You’ll Learn

  1. Pydantic Structured Outputs - Constraining LLM responses to valid JSON schemas
  2. Cerebras Integration - Ultra-fast inference for real-time page personalization
  3. Template Separation - LLM generates content, templates handle layout/styling
  4. Multi-dimensional Personalization - Language, tone, personality, colors, products

Setup

Install Dependencies

Clone the Repository

This cookbook requires assets (images, templates, user data). Clone the full repository to run the notebook:
The hyper_personalization_assets/ directory contains:
  • data/users.csv - Sample user profiles with personalization preferences
  • templates/email_template.html - Jinja2 HTML template for rendering
  • images/ - Product images in different color variants
  • constants.py - Configuration constants (colors, languages, guidance)

Load API Keys

Get your Cerebras API key at https://cloud.cerebras.ai (free tier available).

Part 1: Pydantic Schemas

Pydantic schemas ensure the LLM returns structured, validated JSON. This is crucial for reliable template rendering.

Why Pydantic Schemas Matter

BenefitDescription
Type SafetyValidates LLM output matches expected structure
Auto-documentationField descriptions guide the LLM
Error HandlingCatches malformed responses before rendering
IDE SupportAutocomplete and type hints in your code

Part 2: Configuration Constants

The constants are imported from hyper_personalization_assets/constants.py. Here’s what they define:

Part 3: Content Generation Function

This function calls the Cerebras API with a structured output schema. The LLM is constrained to return valid JSON matching our PageContent schema.

Key Implementation Details

  1. Schema-constrained generation: The response_format parameter forces the LLM to return valid JSON
  2. Pydantic validation: PageContent(**content_dict) validates the response
  3. Performance tracking: We measure generation time and token usage
  4. Concise prompts: Shorter prompts = faster inference

Part 4: Template Rendering

Jinja2 combines LLM-generated content with user-specific styling (colors, images) into the final HTML page.

Part 5: Load User Data

User profiles are loaded from CSV. Each user has unique preferences that drive personalization.
Example output:

Part 6: Generate & Display

This helper orchestrates the full pipeline: generate content → render template → display inline.

Part 7: Generate Personalized Pages

Let’s generate pages for users with different language, tone, and personality combinations.

Example Results

Here are three personalized pages generated for different users: Personalized page for Alex - casual English with red accent Alex’s page: Casual tone, English, red accent color, extroverted personality Personalized page for Maria - friendly Spanish with green accent Maria’s page: Friendly tone, Spanish, green accent color, balanced personality Personalized page for Klaus - formal German with white accent Klaus’s page: Formal tone, German, white accent color, introverted personality

Why This Matters

Research shows that hyper-personalization significantly increases user engagement. According to Zarouali et al. (2020), personalized content that adapts to individual preferences including tone, and messaging leads to higher perceived relevance and stronger behavioral intentions compared to generic content. With Cerebras’ ultra-fast inference, this level of personalization becomes practical for real-time web experiences. What used to require batch processing or slow generation can now happen at page-load speed, creating truly dynamic user experiences.

Performance

MetricValue
Average generation time~0.4s per page
Tokens per page~800-900
Languages supportedEnglish, Spanish, German (extensible)
Personalization dimensions6 (language, tone, personality, color, gender, background)
Cerebras enables real-time personalization at scale—generate thousands of unique pages per minute.

Summary

What We Built

A hyper-personalized web page system where pages adapt to each visitor:
  • Preferred colors - Visual styling matches user preferences
  • Tone & personality - Content adapts from formal to casual
  • Products - Featured items match user demographics
  • Language - Full multilingual support
All powered by Cerebras’ ultra-fast inference (~0.4s per page), making real-time personalization practical at scale.

Key Patterns

  1. Schema-constrained generation: Use response_format with JSON schema for reliable outputs
  2. Pydantic validation: Validate all LLM responses before use
  3. Template separation: LLM generates text, templates handle layout/styling
  4. Concise prompts: Shorter prompts reduce latency and cost

Next Steps

  • Add A/B testing for different content variations
  • Implement click tracking and conversion analytics
  • Add more personalization dimensions (purchase history, browsing behavior)
  • Deploy as a real-time API for e-commerce personalization

Resources

Acknowledgements

Thank you to the Cerebras team, particularly, Ryan, Ryann, and Neeraj, for their support and feedback during the development of this cookbook.