TalentSync

AI resume builder and ATS optimizer for job seekers. Tailored resumes, outreach, and interview prep from one profile.

Question generation engine

The Question Generation Engine is an AI-powered system that generates interview questions tailored to a candidate’s profile, the target role, and the interview format. It combines a configurable difficulty distribution, optional role-based templates, and LLM prompts to produce diverse, non-repeating questions. The engine supports both technical and behavioral assessments, integrates with coding challenges, and adapts question selection dynamically across interview stages. Anti-cheating safeguards include integrity tracking (e.g., tab switching) and code sandboxing for coding rounds.

Repository layout#

The Question Generation Engine spans several modules:

  • Prompt definition for question generation
  • Data models for questions, templates, and interview configuration
  • Question generation service with template and LLM-backed logic
  • Orchestrator that wires generation into the interview flow
  • Session management for state and integrity tracking
  • Routes exposing interview APIs with streaming support
  • Supporting services for answer evaluation and code execution

Building blocks#

  • QuestionGenerator: Central class that builds question lists from difficulty distributions, optionally pulls from templates, and falls back to LLM-generated questions. It avoids repeats by tracking previously asked questions and selects question types cyclically.
  • Prompt Template: Defines the system and human messages guiding the LLM to produce structured, role-appropriate questions with expected keywords and follow-ups.
  • Templates: Predefined question banks per role with difficulty, topic, and optional code challenges. These are used to fill gaps when templates are selected.
  • InterviewGraph: Integrates generation into the interview lifecycle, passing candidate profile and configuration to the generator.
  • SessionManager: Tracks interview state, integrity events (e.g., tab switches), and persists sessions.
  • AnswerEvaluator and CodeExecutor: Support evaluation and secure execution for coding questions, complementing question generation.

How it fits together#

The engine orchestrates question generation within the broader interview flow. The route handlers create sessions, which trigger the graph to generate questions. The generator uses templates and/or LLM prompts to produce questions, which keeps variety and avoids repetition. Integrity events are recorded to detect potential cheating, and coding questions are executed in a sandboxed environment.

QuestionGenerator class#

The QuestionGenerator builds a list of InterviewQuestion objects from:

  • Difficulty distribution: Ensures requested counts per difficulty, padding with fallbacks if needed.
  • Template selection: Uses predefined templates when provided to fill questions first.
  • LLM generation: Falls back to LLM when templates are exhausted or unavailable.
  • Non-repetition: Tracks previously asked questions to avoid duplicates.
  • Dynamic question types: Cycles through technical, behavioral, and role-based categories.

Prompt engineering approach#

The prompt template establishes:

  • Role and difficulty framing
  • Topic focus and question type
  • Candidate background context
  • Existing questions to avoid repetition
  • Expected JSON output with question text, keywords, and follow-ups

Parameter configuration and question categorization#

  • InterviewConfig controls role, number of questions, difficulty distribution, optional template/topic, and coding flags.
  • QuestionSource categorizes questions as resume-based, role-based, behavioral, technical, or coding.
  • DifficultyLevel drives question selection and pacing.

Template-Based question selection#

Templates define:

  • Roles and topics
  • Question banks with difficulty and expected keywords
  • Optional code challenges
  • Coding language preferences

The generator selects template questions matching difficulty and not yet asked, falling back to LLM when needed.

Dynamic question selection based on candidate responses#

While the generator itself does not alter future questions based on a single response, the broader interview graph advances to the next question after evaluation. Integrity events (e.g., tab switches) are tracked and surfaced for review, indirectly influencing the final summary and recommendations.

Question diversity and anti-cheating mechanisms#

  • Diversity: The generator cycles question types (technical, behavioral, role-based) and avoids repeats by tracking existing questions.
  • Anti-cheating:
  • Integrity events recording (e.g., tab switches) are stored and counted.
  • Coding questions execute in a sandbox with language-specific timeouts, output limits, and dangerous-pattern checks.
  • Tab switch thresholds flag sessions for review.

Examples of generated question patterns#

  • Technical coding rounds (e.g., Software Engineer): Algorithmic challenges with code challenges embedded in questions.
  • Behavioral assessments: STAR-focused questions aligned with role expectations.
  • Panel interviews: Mixed difficulty and type progression to maintain engagement and depth.

These patterns derive from built-in templates and the LLM prompt’s structured output schema.

Dependencies#

The QuestionGenerator depends on:

  • Prompt template for LLM invocation
  • Enums for difficulty and question source
  • Models for InterviewQuestion and InterviewConfig
  • Templates for pre-defined question banks
  • Graph and SessionManager for orchestration and persistence

Performance#

  • Prompt construction and LLM invocation are asynchronous; keep prompts small and minimal payload sizes.
  • Template-first strategy reduces LLM calls when templates are available.
  • Non-repetition tracking uses a list of strings; for very large interviews, consider hashing or indexing for O(1) lookups.
  • Streaming evaluation and code execution improve perceived latency; keep prompt sizes reasonable to avoid timeouts.

Troubleshooting#

  • LLM generation failures: The generator falls back to curated fallback questions and sets a default behavioral source.
  • JSON parsing errors: The parser extracts content as-is when JSON is invalid.
  • Session not found or mismatched question: Route handlers raise explicit HTTP errors for invalid states.
  • Integrity concerns: Excessive tab switches are flagged for manual review.