Skip to content

Conversation

@Gavin2318
Copy link

Repro:
poetry run python src/main.py --tickers NVDA
Select Charlie Munger
Select DeepSeek R1

when the code runs to line 124, src/agents/charlie_munger.py

        munger_output = generate_munger_output(
            ticker=ticker, 
            analysis_data=analysis_data,
            state=state,
            agent_id=agent_id,
        )

then line 55, src/utils/llm.py

result = llm.invoke(prompt)

The LLM output message below:

{
  "signal": "neutral",
  "confidence": 55.0,
  "reasoning": "The business showcases a formidable moat with exceptional ROIC (>15% in 8/10 periods) and pricing power (63% gross margins), demonstrating classic competitive advantages through intellectual property and scale. However, applying the margin of safety principle from value investing reveals fatal valuation issues: a mere 0.5% FCF yield and 92% premium to reasonable value mean we're paying a foolish price for future growth. Furthermore, inverting the problem highlights critical risks – revenue and margin volatility (49.6% growth with high fluctuations, 34.1% margins with 11.2% volatility) violates our requirement for predictable cash flows, while moderate share dilution erodes per-share value. Management's conservative debt (D/E 0.13) and cash conversion (FCF/NI 1.05) are praiseworthy, but cannot offset the valuation excess. As I often say, 'The price you pay determines your rate of return' – here, we abstain despite the quality."
}

then in line 59, src/utils/llm.py, it outputs None, since it didn't find ```json

parsed_result = extract_json_from_response(result.content)

To fix this issue, I add code below to try to extract json content directly when three is no ```json in the LLM output

return json.loads(content) inside function extract_json_from_response

def extract_json_from_response(content: str) -> dict | None:
    """Extracts JSON from markdown-formatted response."""
    try:
        json_start = content.find("```json")
        if json_start != -1:
            json_text = content[json_start + 7 :]  # Skip past ```json
            json_end = json_text.find("```")
            if json_end != -1:
                json_text = json_text[:json_end].strip()
                return json.loads(json_text)
        # Try to extract json directly
        return json.loads(content)
    except Exception as e:
        print(f"Error extracting JSON from response: {e}")
    return None

@virattt
Copy link
Owner

virattt commented Jul 29, 2025

I like it, will take a closer look

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants