# Agentic AI Module 3 - Exercise 2: Reflection + Rewrite

**URL:** <https://community.deeplearning.ai/t/agentic-ai-module-3-exercise-2-reflection-rewrite/894526>\
**Category:** Agentic AI\
**Tags:** week-module-3, dl-ai-learning-platform\
**Created:** [August 11, 2026, 2:12am UTC](https://community.deeplearning.ai/t/agentic-ai-module-3-exercise-2-reflection-rewrite/894526 "2026-08-11T02:12:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Murali7](https://avatars.discourse-cdn.com/v4/letter/m/6f9a4e/32.png) [@Murali7](https://community.deeplearning.ai/u/Murali7)\
**Post date:** [August 11, 2026, 2:12am UTC](https://community.deeplearning.ai/t/agentic-ai-module-3-exercise-2-reflection-rewrite/894526/1 "2026-08-11T02:12:15Z")

</div>

I m trying to execute the exercise 2 **Exercise 2: Reflection + Rewrite.** But when I execute I get the output below

```auto
Failed test case: reflection_and_rewrite raised Exception with raw text: The output of the LLM was not valid JSON. Adjust your prompt..
Expected: no exception
Got: The output of the LLM was not valid JSON. Adjust your prompt.

```

I was curious so I printed the llm\_output and notice that the format appears to be JSON. But notice when I print the entire JSON structure is embedded inside _ **```json```** _

See below output of llm\_output

````auto
LLM Output ```json
{
  "reflection": {
    "strengths": "The report presents a comprehensive overview of the subject matter, demonstrating a strong understanding of the key concepts and relevant literature. The methodology is clearly outlined, allowing for reproducibility of results.",
    "limitations": "The report lacks depth in the analysis of certain critical variables, which may affect the overall conclusions. Additionally, some sections are overly verbose, which could detract from the clarity of the arguments presented.",
    "suggestions": "To enhance the report, consider condensing sections that are repetitive or overly detailed. Incorporating more recent studies and data could also strengthen the arguments. A clearer framework for presenting findings would improve readability.",
    "opportunities": "There is an opportunity to expand the discussion on implications of the findings, particularly in relation to practical applications. Engaging with interdisciplinary perspectives could also enrich the analysis."
  },
  "revised_report": {
    "title": "An In-Depth Analysis of [Subject Matter]",
    "introduction": "This report aims to provide a thorough examination of [subject matter], highlighting key findings and their implications. The methodology employed ensures that the results are both reliable and applicable.",
    "methodology": "The research methodology is outlined as follows: [briefly describe methodology]. This approach allows for a comprehensive understanding of the variables at play.",
    "findings": "The findings indicate that [summarize key findings]. These results are consistent with previous studies, yet they also reveal new insights that warrant further exploration.",
    "discussion": "The implications of these findings are significant. They suggest that [discuss implications]. Furthermore, integrating insights from related fields could provide a more holistic understanding of the topic.",
    "conclusion": "In conclusion, this report underscores the importance of [reiterate main points]. Future research should aim to address the limitations identified and explore the opportunities for further inquiry."
  }
}
```

````

Can someone highlight or point a hint of what I am doing wrong?

---

<div class="post-metadata">

**Author:** ![arman101](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/arman101/32/123937_2.png) [@arman101](https://community.deeplearning.ai/u/arman101)\
**Post date:** [August 11, 2026, 7:36am UTC](https://community.deeplearning.ai/t/agentic-ai-module-3-exercise-2-reflection-rewrite/894526/2 "2026-08-11T07:36:04Z")

</div>

The LLM is wrapping its JSON response inside markdown code fences (````json ... ````). That’s what’s breaking the parser — it expects raw JSON, not JSON inside a markdown block.

The fix is in your prompt. You need to explicitly tell the model to return **only** the JSON object, with no markdown formatting, no code fences, no extra text before or after it.

Look at how you’re currently instructing the LLM about the output format and make the constraint more explicit. Something along the lines of “respond with only the JSON object, do not wrap it in markdown code blocks” usually does the trick.

If the issue persists after that, you can also try starting your format instruction with a concrete example of what the first character of the response should be (i.e., `{`).

---

<div class="post-metadata">

**Author:** ![Murali7](https://avatars.discourse-cdn.com/v4/letter/m/6f9a4e/32.png) [@Murali7](https://community.deeplearning.ai/u/Murali7)\
**Post date:** [August 12, 2026, 12:35am UTC](https://community.deeplearning.ai/t/agentic-ai-module-3-exercise-2-reflection-rewrite/894526/3 "2026-08-12T00:35:38Z")

</div>

> [@arman101](#):
>
> **only** the JSON object, with no markdown formatting, no code fences, no extra text before or after it

Thank you I think making the statement explicit about returning JSON Object worked. Thank you again for the help.
