LLM Code Generation Guide
A quick reference for Large Language Models generating Scriptling code.
Quick Summary
When generating Scriptling code:
- Indentation: Use 4-space indentation for blocks
- Booleans and Null: Use
True/Falsefor booleans,Nonefor null (all capitalized) - Loops: Use
range(n),range(start, stop), orrange(start, stop, step)for numeric loops - Slicing: Use slice notation:
list[1:3],list[:3],list[3:],list[::2],list[::-1] - Dict Iteration: Use
keys(dict),values(dict),items(dict)for dictionary iteration - HTTP Response: HTTP functions return a Response object with
status_code,body,text,headers,urlfields - HTTP Options: HTTP functions accept optional options dictionary with
timeoutandheaderskeys - Import Libraries: Use
import json,import requests,import reto load libraries - JSON Functions: Always use
json.loads()andjson.dumps()for JSON (dot notation) - HTTP Functions: Always use
requests.get(),requests.post(), etc. for HTTP (dot notation) - Regex: Use
re.match(),re.search(),re.findall(),re.sub(),re.split()for regex - Timeouts: Default HTTP timeout is 5 seconds if not specified
- Conditions: Use
eliffor multiple conditions - Augmented Assignment: Use augmented assignment:
x += 1,x *= 2, etc. - Loop Control: Use
breakto exit loops,continueto skip iterations - Placeholder: Use
passas a placeholder in empty blocks - List Append:
append(list, item)modifies list in-place - String Concat: Strings use
+for concatenation - File Extension: Use
.pyfile extension - Status Checks: Check
response.status_codebefore processing - Error Handling: Use
try/except/finallyfor error handling - Raise Errors: Use
raise "message"orraise ValueError("msg")to raise errors - Unpacking: Multiple assignment:
a, b = [1, 2]for unpacking lists - Variadic Args: Use
*argsto collect extra positional arguments into a list - Keyword Args: Use
**kwargsto collect extra keyword arguments into a dictionary
Key Differences from Python
- No
delStatement: Use slice assignment instead — e.g.lst = lst[:n]rather thandel lst[n:] - No Nested Classes: Classes must be defined at the top level of a module
- Single Inheritance Only: Multiple inheritance is not supported
- HTTP Response Format: Response object with
status_code,body,text,headers,urlfields - Default Timeout: HTTP requests have a 5-second default timeout
- No Generators:
yieldis not supported - No Dict Comprehensions: Only list comprehensions are supported
Code Template
import json
import requests
# HTTP with headers and status check
options = {
"timeout": 10,
"headers": {"Authorization": "Bearer token"}
}
resp = requests.get("https://api.example.com/data", options)
if resp.status_code == 200:
data = json.loads(resp.body)
# Process data
result = {"success": True, "count": len(data)}
else:
result = {"success": False, "error": resp.status_code}
# Return structured data
scriptling.mcp.tool.return_object(result)Common Patterns
Error Handling
try:
result = risky_operation()
except Exception as e:
result = None
finally:
cleanup()Loop with Index
for item in items(data):
key = item[0]
value = item[1]
print(key, value)String Building in Loops
# Use join() for efficiency
parts = []
for item in items:
parts.append(str(item))
result = "".join(parts)HTTP POST with JSON
import json
import requests
payload = {"name": "Alice", "email": "[email protected]"}
body = json.dumps(payload)
options = {"timeout": 10, "headers": {"Content-Type": "application/json"}}
response = requests.post("https://api.example.com/users", body, options)
if response.status_code == 201:
created = json.loads(response.body)
print("Created user:", created["id"])See Also
- Language Guide - Complete language reference
- Library Cheat Sheet - Quick library reference
- Python Differences - What’s NOT supported