Created
June 24, 2026 01:29
-
-
Save quantra-go-algo/52564f5300ccdf7b794ea805ff388e9b to your computer and use it in GitHub Desktop.
guardrailed-llm-agent — Step 5: The LLM Risk Manager: Building the Policy Table (snippet 3)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Retry once on parse failure, fall back to rule policy if both fail | |
| for attempt in range(2): | |
| content = deepseek_chat(messages, max_tokens=2000) | |
| try: | |
| obj = parse_json(content) | |
| return obj.get('policy', {}) | |
| except ValueError as e: | |
| if attempt == 1: | |
| print(f'Parse failed twice for {month_start.date()}, using rule fallback') | |
| return rule_policy(stats) # deterministic fallback |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment