LLM-Generated 3D Scenes: Instruction Validation and Speed Measurement

    This article uses a small Text-to-World 3D web application to examine how high-throughput LLM output can be used in engineering practice. It defines TTFT, TPS, and output-quality metrics; describes a repeatable measurement protocol; and outlines the application architecture and data flow. It then details JSON instruction schemas, cleaning and validation, retry logic, streaming parsing, and a frontend executor, followed by a quality checklist and a discussion of why speed and reasoning ability should be measured separately.

    Developers using AI programming tools often find waiting to be the most frustrating part. Changing a component can take more than ten seconds, and refactoring a module can take a minute. By then, attention has already moved to the next step, and focus is broken.

    In the past year or two, faster large language models have become increasingly available, and code generation has shifted from line-by-line input to block-by-block output. As speed increases, a natural question follows: does the model’s reasoning ability decline? This article does not assume an answer. Instead, it uses a complete 3D web application as an example to show how a high-throughput model can be used in engineering and how to determine whether it is suitable for your project.

    1. Define Metrics and Measurement Protocol First

    When evaluating model speed, three metrics are usually considered.

    1. TTFT (Time To First Token): the time from sending a request to receiving the first token. It determines how long users wait before seeing a response.
    2. TPS (Tokens Per Second): the generation speed after the first token. For outputs of the same length, higher TPS means faster completion.
    3. Output quality: speed does not mean the result is usable. The model must maintain an understanding of the project structure, avoid logical breaks, and avoid inventing interfaces or parameters that do not exist.

    The three metrics should be considered together. Looking only at TPS ignores first-token latency. Looking only at total time makes it impossible to distinguish a slow model from a task that simply produces a large output. Vendor-published TPS usually covers only the model decoding stage and excludes queueing, network, and prompt-processing time, so it cannot be treated directly as the end-to-end speed of your system.

    Measurement Steps

    Step 1: Fix the test set. Collect 30 to 50 instructions from real usage scenarios, covering three instruction types (spawn_object, set_environment, and add_effect), and add boundary inputs such as empty descriptions, extremely long descriptions, and ambiguous descriptions. All models use the same test set.

    Step 2: Record timestamps. The client records t0 before sending the request, t1 when the first content chunk arrives, and t2 when the streaming response ends. The server also records the request arrival time and the time the upstream request is sent, so network time and model time can be distinguished.

    Step 3: Calculate metrics. TTFT equals t1 minus t0. Total time equals t2 minus t0. For output token count, prefer the usage field returned by the API. If the API does not return it, estimate with the same tokenizer and note the estimation method in the report. TPS equals output token count divided by (t2 minus t1).

    Step 4: Record test conditions. Every test should record the model name and version, request region, concurrency, network environment, whether caching is enabled, max_tokens, and temperature. Numbers without these conditions cannot be compared.

    Step 5: Repeat tests and take statistical values. Run each instruction at least 5 times and report the median and P90. Do not keep only the best single result. Network fluctuations and server-side queueing can cause large differences between single runs.

    Step 6: Check output quality at the same time. Speed numbers only show whether the model is fast. The quality checklist in Section 5 is still needed to determine whether the model is correct.

    2. Project Background: Text-to-World

    Text-to-World is a small 3D web demo. Users move through the scene with the WASD keys, rotate the view with the mouse, and describe desired changes in natural language in an input box, for example: “Spawn a cyberpunk castle ahead and switch to a stormy night.”

    The backend passes this sentence to a large language model, and the model returns structured JSON instructions. The frontend reads these instructions, instantiates objects, switches environment lighting, and attaches particle effects. The user provides natural language, while scene changes are executed by deterministic code. The model translates intent, and the code ensures predictable results.

    The project includes movement and view controls, streaming responses, a weather system, particle effects, NPC generation, and portals. The feature set is not large, but each capability requires the model to output accurate parameters, making it suitable for testing the stability of structured output.

    To reproduce this project, you need only a frontend build environment, a backend runtime, and an API key that can access a large language model. Specific dependency versions are determined by the project lockfile. The API key is injected into the backend through environment variables and is not written into code or logs.

    3. Architecture and Data Flow

    The system data flow has four stages.

    1. Input capture: the frontend captures user input and sends it to the backend through an HTTP request.
    2. Instruction generation: the backend assembles a system prompt that specifies allowed instruction types and output format, then calls the large language model.
    3. Streaming transmission: the backend pushes model output to the frontend in chunks to reduce user waiting.
    4. Scene rendering: the frontend executor parses instructions and calls 3D engine APIs to complete rendering.

    The frontend uses a component-based framework with a strongly typed scripting language and a mainstream Web 3D rendering engine, with atomic CSS for styling. The backend uses a lightweight runtime and a web framework to provide APIs.

    The security boundary is clear. All model calls are placed on the backend, and the frontend communicates only with backend APIs, so the API key never appears in the browser. The backend applies request rate limits per user or IP to prevent key abuse. User input and keys in logs must be redacted, keeping only request IDs, latency, and error types.

    4. Instruction Format, Validation, and Retry

    The instruction format is central to this project. The JSON returned by the model must be directly parseable by the frontend; otherwise, the scene cannot update. The project defines three instruction types:

    Instruction Required fields Description
    spawn_object command, object_name, position Spawns an object at specified coordinates. position is a numeric array of length 3. scale defaults to 1 and must be greater than 0.
    set_environment command, time_of_day, weather_type Sets the environment. time_of_day is one of day, dusk, or night; weather_type is one of clear, rain, or storm; fog_density is an optional number between 0 and 1.
    add_effect command, effect_type, target_object Adds a particle effect. effect_type must be in a predefined list; duration is optional, positive, and measured in seconds.

    Example output:

    1. [
    2. {"command": "spawn_object", "object_name": "castle", "position": [0, 0, -20], "scale": 1.5},
    3. {"command": "set_environment", "time_of_day": "night", "weather_type": "storm", "fog_density": 0.8}
    4. ]

    The prompt must explicitly state: output only a JSON array, no explanatory text, and no Markdown code fences. Even so, the model occasionally adds fences or an extra sentence. Therefore, the backend must clean and validate the output itself.

    Cleaning and Validation

    1. Remove residual code fences and text outside the array.
    2. Try to parse the JSON. If parsing fails, log the error and enter the retry flow.
    3. Check each instruction for field types, value ranges, enum values, and array length. Discard non-compliant instructions and write logs that record the instruction number and failure reason.
    4. If all instructions are discarded, return a readable error message to the user instead of letting the frontend crash.

    Below is an example of a validation failure:

    1. {"command": "spawn_object", "object_name": "castle", "position": [0, 0], "scale": -1}

    This instruction has two problems: position has length 2 instead of 3, and scale is negative rather than greater than 0. The validator discards the instruction and records both error reasons.

    Retry Strategy

    Retries are triggered only when JSON cannot be parsed or when no valid instruction remains after cleaning. Instructions with invalid fields do not trigger a full retry; they are simply discarded to avoid unnecessary requests.

    Set a timeout for each request. The timeout value should be determined by the team based on the model’s normal response time. A timeout is treated as one failure.

    Retry at most twice. Before each retry, use exponential backoff, increasing the wait time each time, and add random jitter to prevent multiple requests from being resent at the same time.

    For the second and later requests, include the previous error information in the conversation, for example: “The previous output could not be parsed as JSON, with an error on the third line. Please output only a valid JSON array.” This helps the model understand what went wrong.

    Failure logs record the request ID, attempt count, error type, and truncated raw output. Raw output must be redacted before being written to logs.

    If all three attempts fail, the user should see: “This time no executable scene change was generated. Please try a different description.” The interface does not display raw error details.

    5. Streaming Parsing and Frontend Executor

    Streaming lets users see changes earlier, but it also introduces parsing problems. Data chunks returned over the network may split JSON at any position.

    Streaming Parsing

    It is recommended that the model output JSON Lines format, with one JSON object per line, rather than one complete array. This allows the backend to split by line and parse each line after it is complete, which is much simpler to implement than incrementally parsing an array.

    The backend maintains a buffer. Each time a data chunk is received, it is appended to the buffer and then split by newline. If the last segment has no newline, it may be a partial JSON fragment, so it is kept in the buffer and waits for subsequent data chunks to complete it.

    Only complete lines that parse successfully are pushed to the frontend. Partial JSON is neither executed nor pushed.

    The transport protocol can be SSE (Server-Sent Events) or NDJSON. SSE is suitable for direct browser subscription and includes reconnection mechanisms. NDJSON is transmitted through a normal chunked response and is more direct to implement. Either is acceptable; the key is that message boundaries are clear.

    Errors need a separate message type. The backend pushes an error frame such as {"type":"error","message":"..."}, and the frontend displays a prompt based on it instead of waiting for a timeout.

    When the user cancels a request, the frontend aborts the connection through AbortController. When the backend detects that the connection is closed, it should immediately terminate the upstream model request to avoid continuing to consume quota.

    Executor

    The core of the executor is a dispatch table that maps each command to its corresponding handler:

    • spawn_object: creates an object in the scene and records the object ID for later reference.
    • set_environment: updates lighting and weather state.
    • add_effect: attaches a particle system to the object specified by target_object.

    The frontend validates again before execution. Backend validation is the first gate; frontend validation is the second gate that prevents abnormal data from entering the rendering layer.

    Each instruction carries a unique ID. The executor records processed IDs and skips duplicate IDs directly. This prevents the same instruction from being executed twice during network retransmission or retries.

    Batch instruction execution requires a strategy. Per-instruction execution is simple to implement, but a mid-batch failure can leave a half-completed scene. Transactional execution first applies the entire batch to a snapshot, commits only if all instructions succeed, and rolls back to the snapshot on failure. This project has a small instruction volume, so transactional execution is suitable. When the instruction volume is large, it can be changed to per-instruction execution with each result recorded.

    6. Quality Evaluation Checklist

    After speed measurement, output quality must also be evaluated. The following metrics can be used directly with the test set.

    Metric Calculation Description
    Structural validity rate Number of responses parseable as valid JSON divided by total responses Measures whether format constraints are effective
    Field completeness rate Number of instructions with complete fields divided by total instructions Checks whether required fields are missing
    Enum correctness rate Number of instructions with valid enum values divided by total instructions Checks values such as time_of_day and weather_type
    Scene executability rate Number of instructions successfully executed by the executor divided by total instructions Reflects end-to-end usability
    Semantic match rate Proportion of manually sampled cases where the scene matches the description For example, whether “stormy night” actually switches to night and storm
    TTFT and TPS Calculated according to the measurement steps in Section 1 Report median and P90

    Thresholds are set by the team according to scenario risk. For an application like this one that directly affects the scene, structural validity rate and scene executability rate should be close to 100%; otherwise, users will frequently encounter error prompts. Semantic match rate requires manual sampling, and the sample size can be adjusted according to the size of the test set.

    7. Judging Reasoning Ability

    Higher speed does not mean lower reasoning ability, nor does it mean higher reasoning ability. The two must be measured separately.

    The test set in this article covers only the instruction conversion task in Text-to-World, and the conclusions apply only to this task. To judge a model’s reasoning ability, use an independent reasoning task set and compare the accuracy of different models under the same conditions. Extending the results in this article to other tasks requires new measurements.

    For most engineering projects, the more practical question is whether the model can reliably output executable results and whether the system can handle failures gracefully. Implementing validation, retries, streaming parsing, and the executor well is more valuable than pursuing a single speed number.