Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
LLM Prompting Class
00:00
5 left

LLM Prompting Class

MediumPython

Problem

Implement a class that initializes an LLM in the constructor, builds a prompt inside a method, and sends it to the LLM to produce structured output.

Asked in the Technical assessment (OA) stage. No framework; imports are prebuilt, with LeetCode-style function bodies.

For grading, implement structured_answer(request, llm_response). The function must build a prompt from request, parse the supplied LLM response as JSON, and return an object containing answer, confidence, and sources. Raise ValueError when the response is invalid JSON or misses a required field.

Input and Output

request is an object containing question and an optional context. llm_response is a JSON string. Return the parsed object when valid.

Constraints

  • request contains a string field named question.
  • request may contain an optional string field named context.
  • llm_response is a string.
  • A valid response must be a JSON object containing answer, confidence, and sources.

Function Signature

def structured_answer(request, llm_response):
Interviewer

Your question is LLM Prompting Class. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.