The DAML validation tool now preserves full LLM context in addition to structured JSON extraction. This ensures we get maximum value from the LLM analysis we're paying for.
# Extract JSON
result = json.loads(content)
# Discard everything else
return AuthorizationExtractionResult(
model=model,
confidence=confidence,
reasoning="Brief explanation from JSON"
)Problem: LLM often adds valuable context/explanations that got thrown away!
# Extract JSON for structured data
json_content = content[first_brace:last_brace + 1]
result = json.loads(json_content)
# BUT ALSO preserve full LLM response
return AuthorizationExtractionResult(
model=model,
confidence=confidence,
reasoning="Brief explanation from JSON",
llm_full_response=content # Full context preserved!
)Benefit: We keep both structure AND insights!
template PaymentApprovalRequest
with
requester: Party
approvers: [Party]
where
signatory requester
observer approvers
choice ApprovePayment : ()
with
approver: Party -- Choice parameter
controller approver
do
assertMsg "Approver must be authorized" (approver `elem` approvers)
return ()
JSON (structured):
{
"template_name": "PaymentApprovalRequest",
"signatories": ["requester"],
"observers": ["approvers"],
"controllers": {"ApprovePayment": ["approver"]},
"confidence": 0.8,
"reasoning": "Choice parameter with runtime validation"
}Extra Context (insights):
The controller 'approver' is a choice parameter that gets validated
at runtime against the 'approvers' field using `elem`. This is a
common DAML pattern for dynamic authorization where any member of
a list can exercise the choice.
The confidence is 0.8 (not 1.0) because this pattern requires
understanding the semantic relationship between the parameter and
the validation logic. The actual controller set is 'approvers',
but it's expressed through runtime validation rather than compile-time
declaration.
This is generally safe IF the validation is correct (which it is here).
{
"valid": true,
"confidence": 0.8,
"issues": [],
"suggestions": [],
"llm_insights": "The controller 'approver' is a choice parameter that gets validated at runtime against the 'approvers' field using `elem`. This is a common DAML pattern for dynamic authorization where any member of a list can exercise the choice.\n\nThe confidence is 0.8 (not 1.0) because this pattern requires understanding the semantic relationship between the parameter and the validation logic..."
}Users learn DAML patterns from the LLM's explanations:
- "This is a common DAML pattern for..."
- "The confidence is X because..."
- "This is safe IF..."
When confidence is lower:
- Users understand WHY the LLM is uncertain
- Clear indication of complex patterns
- Helps users decide if manual review is needed
Full LLM responses are valuable for:
- Understanding why certain decisions were made
- Improving prompts over time
- Training/fine-tuning models
Users see exactly what the LLM "thinks":
- Not a black box
- Can validate LLM reasoning
- Build trust in the system
If users are paying via x402:
- They get EVERYTHING the LLM produced
- Not just extracted data
- Maximum ROI on the LLM call
LLM Response (raw text)
│
├─> Parse JSON → Structured data
│ └─> AuthorizationModel
│ └─> confidence, reasoning
│
└─> Extract insights → Additional context
└─> Text before/after JSON
└─> llm_full_response
└─> llm_insights (in tool response)
@dataclass
class AuthorizationExtractionResult:
model: Optional[AuthorizationModel] # Structured
confidence: float # Structured
reasoning: str # Structured (from JSON)
llm_full_response: Optional[str] # Unstructured (full context)class ValidateDamlResult:
valid: bool
confidence: float
issues: List[str]
suggestions: List[str]
llm_insights: Optional[str] # NEW: Full LLM context exposed{
"valid": true,
"confidence": 1.0,
"llm_insights": "Simple, clear authorization pattern with single signatory and observer."
}Value: Confirms the pattern is straightforward
{
"valid": true,
"confidence": 0.8,
"llm_insights": "Choice parameter with runtime validation. The controller 'approver' is validated against 'approvers' at runtime, which is a common DAML pattern..."
}Value: Explains the complexity and validates the pattern
{
"valid": false,
"should_delegate": true,
"confidence": 0.5,
"llm_insights": "This code uses conditional expressions in the observer declaration that I cannot fully analyze. Manual review recommended to ensure..."
}Value: Clear explanation of why delegation is needed
Parse the insights into categories:
{
"llm_insights": {
"pattern_explanation": "...",
"confidence_reasoning": "...",
"safety_notes": "...",
"recommendations": ["..."]
}
}Identify key insights automatically:
- Security warnings →
⚠️ - Best practices → 💡
- Pattern explanations → 📚
Use insights to improve:
- Identify common misconceptions
- Build FAQ from repeated patterns
- Fine-tune prompts based on useful insights
Track correlation between:
- LLM stated confidence
- Actual accuracy
- Adjust thresholds accordingly
No additional cost! The LLM generates this context anyway (we were just throwing it away).
By preserving it:
- ✅ Zero extra LLM calls
- ✅ Maximum value extraction
- ✅ Better ROI on x402 payments
- ✅ Richer user experience
The LLM Insights feature ensures we extract maximum value from every LLM analysis:
- ✅ Structured data (JSON) for programmatic use
- ✅ Full context (insights) for understanding
- ✅ No extra cost - just better use of existing calls
- ✅ Educational - users learn from LLM explanations
- ✅ Transparent - users see full LLM reasoning
This aligns perfectly with the "Boom! Payment = Boom! Value" philosophy:
- If users are paying for LLM analysis via x402
- They deserve to see ALL the value the LLM provides
- Not just the extracted bits!