GenLayer gl.nondet.web.render() Modes: text, html, and screenshot Explained

The gl.nondet.web.render() function supports three rendering modes—text, html, and screenshot—allowing GenLayer contracts to retrieve web content as plain text, raw HTML, or a visual image.

The gl.nondet.web.render() method in the GenLayer SDK enables smart contracts to fetch external web data for processing within the GenLayer environment. As documented in the genlayerlabs/genlayer-project-boilerplate repository, this nondeterministic function accepts a target URL and a mode parameter to specify the desired output format. Each mode returns a different data type optimized for specific contract logic, from text analysis to visual verification.

Overview of gl.nondet.web.render() Modes

According to the SDK reference in CLAUDE.md, gl.nondet.web.render() accepts three distinct string values for the mode parameter:

  • text – Returns a str containing the page's plain-text content with HTML tags stripped
  • html – Returns a str containing the full raw HTML source of the page
  • screenshot – Returns an Image object representing a visual capture of the rendered page

These modes give developers precise control over how web data enters the contract execution context.

The Three Rendering Modes Explained

text Mode

The text mode extracts readable content from a web page by removing HTML markup, making it ideal for natural language processing tasks. When you call gl.nondet.web.render(url, mode="text"), the function returns a Python string containing the article body or page text without script tags, styles, or markup.

This mode appears in production contracts such as contracts/football_bets.py, where contracts scrape readable information from sports websites.

html Mode

Use the html mode when your contract requires parsing raw markup, extracting specific DOM elements, or verifying page structure. Invoking gl.nondet.web.render(url, mode="html") returns the complete HTML source as a string, including all tags, attributes, and embedded scripts.

This mode suits contracts that perform structured data extraction or checksum validation against page source.

screenshot Mode

The screenshot mode captures a visual rendering of the web page as an Image object. This enables computer vision workflows, UI verification, or oracle logic based on visual state rather than text content.

The integration test file tests/integration/test_new_features.py demonstrates this capability, showing how contracts can pass image data to LLM prompts for visual analysis.

Code Implementation Examples

Fetching Plain Text Content

To extract readable text from an article or documentation page:

url = "https://example.com/article"
page_text = gl.nondet.web.render(url, mode="text")

# Returns: str containing "Article Title\n\nArticle body content..."

Retrieving Raw HTML

To access the full page source for parsing or validation:

url = "https://example.com/page"
raw_html = gl.nondet.web.render(url, mode="html")

# Returns: str containing "<!DOCTYPE html><html>...</html>"

Capturing Visual Screenshots

To obtain an image representation of a dashboard or visual element:

url = "https://example.com/dashboard"
screenshot = gl.nondet.web.render(url, mode="screenshot")

# Returns: Image object compatible with LLM vision inputs

Integrating render() in Smart Contracts

Combine gl.nondet.web.render() with LLM calls for autonomous web analysis:

class ScraperContract(gl.Contract):
    @gl.public.view
    def get_page_summary(self, target_url: str) -> str:
        # Retrieve page as plain text

        page_text = gl.nondet.web.render(target_url, mode="text")
        
        # Process with LLM

        summary = gl.nondet.exec_prompt(
            f"Summarize this text in one sentence:\n{page_text}",
            response_format="text"
        )
        return summary

Source Code Reference

The implementation and usage patterns for gl.nondet.web.render() appear in the following repository files:

These files illustrate how the GenLayer SDK handles nondeterministic web access across different rendering formats.

Summary

  • gl.nondet.web.render() provides three modes—text, html, and screenshot—for retrieving web content in GenLayer contracts
  • text mode returns clean, HTML-stripped strings suitable for NLP tasks
  • html mode returns raw source markup for structural parsing
  • screenshot mode returns Image objects enabling visual verification and computer vision workflows
  • All modes are documented in CLAUDE.md and implemented in the genlayer-project-boilerplate repository

Frequently Asked Questions

What are the valid mode values for gl.nondet.web.render()?

The function accepts exactly three string values for the mode parameter: "text" for plain content extraction, "html" for raw markup retrieval, and "screenshot" for visual image capture. Each mode returns a different Python type (str, str, or Image respectively).

How does the screenshot mode return image data?

When invoked with mode="screenshot", gl.nondet.web.render() returns an Image object rather than a string. This object can be passed directly to LLM vision capabilities within the GenLayer environment or used for on-chain visual verification logic.

Which source files demonstrate gl.nondet.web.render() usage?

The genlayer-project-boilerplate repository contains three key references: CLAUDE.md documents the API specification, contracts/football_bets.py shows text mode in a production contract, and tests/integration/test_new_features.py validates the screenshot mode in integration tests.

Can gl.nondet.web.render() be used in public contract methods?

Yes, as demonstrated in contracts/football_bets.py and the example ScraperContract, gl.nondet.web.render() can be invoked within @gl.public.view methods. Because it is a nondeterministic operation, the GenLayer network reaches consensus on the result through its LLM-based validation mechanism.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →