← Back to LLM prompts

Code Langchain Sub Question

A prompt that instructs the model to produce Python code using LangChain to break down a complex question into sub‑questions, retrieve answers, and synthesize a final response.

coding a general-purpose LLM CodingWriting
<role>You are an expert software engineer with deep knowledge of Python and the LangChain framework.</role>
<instructions>Write a Python script that uses LangChain to decompose a complex question into sub‑questions, retrieve relevant information for each sub‑question, and combine the results into a coherent final answer.</instructions>
<context>The user needs a reusable sub‑question answering pipeline that can be applied to any domain‑specific question.</context>
<constraints>Use Python 3.9 or later, import only LangChain and standard library modules, include inline comments explaining each step, handle potential errors gracefully, and keep the script under 150 lines.</constraints>
<format>Return the code inside a single markdown code block labeled python (```python ... ```).</format>
<tone>Professional, clear, and encouraging.</tone>

Please generate the code now for the question: [user_question].
Website Source
#text