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.
request is an object containing question and an optional context. llm_response is a JSON string. Return the parsed object when valid.
request contains a string field named question.request may contain an optional string field named context.llm_response is a string.answer, confidence, and sources.def structured_answer(request, llm_response):