docs: rewrite prompt techniques, add nondet rules, rename nav#370
docs: rewrite prompt techniques, add nondet rules, rename nav#370MuncleUscles merged 2 commits intomainfrom
Conversation
✅ Deploy Preview for genlayer-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughUpdated navigation metadata labels and substantially revised intelligent-contract documentation: renamed a couple of menu entries, replaced the “Crafting Prompts” doc with a new “Prompt & Data Techniques” focused on LLM-grounding and deterministic checks, and added nondeterminism placement rules; validator setup example versions were updated. Changes
Sequence Diagram(s)sequenceDiagram
participant Dev as Developer (writes prompts/rules)
participant LLM as LLM (generates checks)
participant Sandbox as Sandbox Eval (deterministic)
participant API as External API (leader/validator)
participant Contract as Compliance Prompt / Contract
Dev->>LLM: send rule-generation prompt
LLM->>Dev: return JSON-formatted check expressions
Dev->>Sandbox: pass JSON checks for deterministic eval
Sandbox->>API: fetch deterministic fields (independent leader/validator calls)
API-->>Sandbox: return normalized deterministic fields
Sandbox->>Sandbox: evaluate checks -> produce verified results
Sandbox->>Contract: inject verified "ground truth" into compliance prompt
Contract->>LLM: request final compliance judgement (with ground truth)
LLM-->>Contract: final, structured decision
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…ections - Rewrite crafting-prompts.mdx → "Prompt & Data Techniques" with 5 concrete techniques: JSON responses, stable field extraction, derived status comparison, LLM grounding with programmatic eval, error classification - Add "What Goes Inside vs Outside" section to non-determinism.mdx explaining what must/cannot happen inside nondet blocks (storage writes, contract calls, message emission, nesting) - Rename "Decentralized Applications" → "Frontend & SDK Integration" in nav
b66fc01 to
9dadc20
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
pages/developers/intelligent-contracts/crafting-prompts.mdx (1)
32-32: Small wording polish for docs quality.Use “Markdown” (proper noun) at Line [32], and “error-handling” (hyphenated compound adjective) at Line [198].
Also applies to: 198-198
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@pages/developers/intelligent-contracts/crafting-prompts.mdx` at line 32, Update the wording in the sentence that currently reads 'Without `response_format="json"`, LLMs may wrap output in markdown code fences, add commentary, or return malformed JSON. With it, you get a parsed dict directly.' to use the proper noun "Markdown" (capitalized). Also change the compound adjective at the other location that references error handling to the hyphenated form "error-handling". Locate these phrases in the document by searching for the exact sentence about response_format="json" and the occurrence of "error handling" (or similar) and apply the two small wording edits.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@pages/developers/intelligent-contracts/features/non-determinism.mdx`:
- Around line 21-31: The example references validator_fn but never defines it;
add a validator function (e.g., validator_fn) alongside leader_fn inside
fetch_price that accepts the leader result (or the raw response) and returns a
boolean indicating validity (for example by verifying parse_price(result)
succeeds and the price is within expected bounds), then pass that validator_fn
to gl.vm.run_nondet_unsafe; ensure the symbols match (leader_fn, validator_fn,
fetch_price, gl.vm.run_nondet_unsafe) so the snippet is runnable.
- Around line 54-58: The validator_fn currently divides by leaders_res.calldata
which can be zero; update validator_fn to guard against divide-by-zero by first
checking if leaders_res.calldata is zero (or near-zero) before performing the
ratio compute — e.g., if leaders_res.calldata == 0 (or abs(leaders_res.calldata)
< small_epsilon) return comparison using direct equality or a tolerance-based
absolute difference, otherwise perform the existing relative check using
abs(leaders_res.calldata - my_price) / leaders_res.calldata <= 0.02; reference
validator_fn, leader_fn, and leaders_res.calldata when implementing the guard.
---
Nitpick comments:
In `@pages/developers/intelligent-contracts/crafting-prompts.mdx`:
- Line 32: Update the wording in the sentence that currently reads 'Without
`response_format="json"`, LLMs may wrap output in markdown code fences, add
commentary, or return malformed JSON. With it, you get a parsed dict directly.'
to use the proper noun "Markdown" (capitalized). Also change the compound
adjective at the other location that references error handling to the hyphenated
form "error-handling". Locate these phrases in the document by searching for the
exact sentence about response_format="json" and the occurrence of "error
handling" (or similar) and apply the two small wording edits.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: e0495290-6eeb-468b-8ccd-0718e9177841
📒 Files selected for processing (4)
pages/developers/_meta.jsonpages/developers/intelligent-contracts/_meta.jsonpages/developers/intelligent-contracts/crafting-prompts.mdxpages/developers/intelligent-contracts/features/non-determinism.mdx
| def validator_fn(leaders_res) -> bool: | ||
| if not isinstance(leaders_res, gl.vm.Return): | ||
| return False | ||
| my_price = leader_fn() | ||
| return abs(leaders_res.calldata - my_price) / leaders_res.calldata <= 0.02 |
There was a problem hiding this comment.
Guard against divide-by-zero in validator ratio check.
Line [58] divides by leaders_res.calldata; if that value is 0, this example throws.
Suggested fix
- return abs(leaders_res.calldata - my_price) / leaders_res.calldata <= 0.02
+ denom = max(abs(leaders_res.calldata), 1e-9)
+ return abs(leaders_res.calldata - my_price) / denom <= 0.02📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| def validator_fn(leaders_res) -> bool: | |
| if not isinstance(leaders_res, gl.vm.Return): | |
| return False | |
| my_price = leader_fn() | |
| return abs(leaders_res.calldata - my_price) / leaders_res.calldata <= 0.02 | |
| def validator_fn(leaders_res) -> bool: | |
| if not isinstance(leaders_res, gl.vm.Return): | |
| return False | |
| my_price = leader_fn() | |
| denom = max(abs(leaders_res.calldata), 1e-9) | |
| return abs(leaders_res.calldata - my_price) / denom <= 0.02 |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@pages/developers/intelligent-contracts/features/non-determinism.mdx` around
lines 54 - 58, The validator_fn currently divides by leaders_res.calldata which
can be zero; update validator_fn to guard against divide-by-zero by first
checking if leaders_res.calldata is zero (or near-zero) before performing the
ratio compute — e.g., if leaders_res.calldata == 0 (or abs(leaders_res.calldata)
< small_epsilon) return comparison using direct equality or a tolerance-based
absolute difference, otherwise perform the existing relative check using
abs(leaders_res.calldata - my_price) / leaders_res.calldata <= 0.02; reference
validator_fn, leader_fn, and leaders_res.calldata when implementing the guard.
Summary
response_format="json")spawn_sandbox)[EXPECTED]vs[EXTERNAL])Test plan
python scripts/lint-code-examples.pySummary by CodeRabbit