Practical Guide to LLM Code Execution, 3D Scripting, and Financial RAG

    As large language model (LLM) post-training techniques evolve, evaluating model capabilities has expanded beyond simple text conversations to include AI code execution, spatial reasoning, and complex business logic. This article explores architectural designs and enterprise implementation strategies for three key scenarios: building a cost-effective sandbox for AI code execution, generating 3D assets via direct scripting, and mitigating hallucinations in financial Retrieval-Augmented Generation (RAG) systems.

    With the continuous evolution of post-training techniques for large language models (LLMs), industry evaluation of model capabilities has expanded beyond simple text conversations to include AI code execution, spatial reasoning, and complex business logic. Recently, some open-source models have drawn attention for their performance in code generation, 3D asset creation, and complex financial reasoning following new post-training upgrades. From a general technical practice perspective, this article helps developers master the architecture design and enterprise-level implementation for these three scenarios.

    1. AI Code Execution: Building a Cost-Effective Sandbox Loop

    The core challenge in the industry is that while top-tier models can handle highly complex tasks, their inference costs are high. Lightweight models are cheaper but often lack the capability for multi-step code debugging. New-generation post-trained models optimize their policy networks to reduce token consumption per task while maintaining a high success rate.

    Common Pitfalls and Best Practices

    When building code agents, focus on the following:

    • Sandbox Permissions: Prevent process escape within containers. It is recommended to use read-only filesystem mounts and network whitelists.
    • Token Overflow Strategy: Set a maximum context length. Truncate or summarize error logs before sending them back to the model.
    • Temperature Settings: For execution tasks, set the temperature to 0 or near 0 to reduce unstable outputs caused by randomness.

    Sandbox + Feedback Loop Architecture Example

    The following pseudocode illustrates key dependency initialization and exception handling details. Replace it with actual SDKs (such as docker-py and openai) in real-world usage:

    1. # Example: Model-driven code execution and debugging loop (pseudocode, replace with real SDKs)
    2. import os
    3. import subprocess
    4. # [Note] Hardcoding API keys is prohibited; they must be read from environment variables
    5. MODEL_API_KEY = os.environ.get("MODEL_API_KEY")
    6. # The following is a pseudocode illustration; replace with actual SDK calls:
    7. # sandbox = DockerSandbox(image="python:3.11-slim", timeout=30)
    8. # model_client = LLMClient(api_key=MODEL_API_KEY, model="your-model")
    9. def execute_code_with_agent(code_snippet, max_retries=3):
    10. for attempt in range(max_retries):
    11. # Execute in the sandbox, capturing both stdout and stderr
    12. result = sandbox.run(
    13. code=code_snippet,
    14. capture_output=True # Capture standard and error outputs simultaneously
    15. )
    16. if result.returncode == 0:
    17. return result.stdout
    18. # Extract error info (truncate to prevent Token overflow) and ask the model to fix it
    19. error_log = result.stderr[:2000]
    20. code_snippet = model_client.generate(
    21. prompt=f"Execution error: {error_log}\nPlease fix the following code:\n{code_snippet}"
    22. )
    23. return "Execution failed, maximum retries exceeded"

    Combined with cost-effective models, this pattern can be used for scenarios like automated testing and batch script generation, effectively controlling marginal costs.

    2. Generating 3D Assets with LLMs: Toolchain Selection and Scripting

    Traditional approaches often rely on external Model Context Protocols or dedicated plugins for bridging. Today, LLMs can expand their capabilities from text to 3D assets by directly writing scripts for professional modeling tools. This requires the model to understand coordinate transformations, material rendering, and geometric topology.

    Three-Layer Script Structure

    LLM-generated 3D scripts typically include:

    • Geometry Generation Layer: Parametrically calls basic primitives (cubes, spheres, curve lofts) to build the main structure.
    • Material and Lighting Layer: Defines RGB values, roughness, metallicity, and light attenuation methods.
    • Spatial Layout Layer: Calculates translation, rotation, and scaling matrices to assemble multiple components.

    Toolchain Comparison

    The following compares common 3D tool scripting interfaces for developers to choose based on their needs:

    Tool Scripting Interface Learning Curve API Version Advantages Use Cases
    Blender Python API (bpy) Low 3.x+ Open-source, rich community resources Rapid prototyping, independent creation
    Maya MEL / Python High 2024+ Industrial-grade pipeline support Film/animation, game assets
    Houdini VEX / Python Medium-High 19.5+ Strong procedural generation VFX, complex geometry

    Cloud Collaboration Architecture

    In practice, enterprises can pass LLM-generated 3D scripts to a cloud rendering farm for high-precision output, integrating object storage and CDN for online preview and distribution. The recommended architecture is: Model generates script -> Upload to object storage -> Trigger cloud rendering task -> Frontend preview and export video or dynamic image. This forms a creation-storage-sharing loop. Actual selection should consider compliance and cost.

    3. Financial RAG Hallucination Mitigation: Compliant Implementation

    Financial scenarios have strict requirements for LLM long-context retrieval, cross-document verification, and multi-step numerical reasoning. Hallucinations are particularly intolerable. According to public benchmark reports, hallucination rates in financial tasks have decreased for some models, but actual performance depends on the model version and testing methodology. Developers must verify this independently.

    Investment Workflow and Prompt Template

    • Target Screening: Extract key metrics like PE, PB, and ROE from unstructured financial reports.
    • Cross-Document Verification: Cross-reference annual reports with quarterly reports and audit reports to identify data discrepancies.
    • Earnings Analysis: Perform multi-step deductions based on historical data to forecast earnings ranges.

    Here is a prompt template example for cross-document verification:

    1. You are a financial analysis assistant. Please answer the question based on the retrieved document snippets below and cite the data sources.
    2. If the relevant values are not mentioned in the documents, explicitly state "Not found" and do not fabricate information.
    3. [Document Snippets]
    4. {retrieved_context}
    5. [Question]
    6. {user_question}
    7. Please output in JSON format: {"answer": "...", "source": "Document ID-Paragraph", "confidence": "high/low"}

    After generation, introduce a “self-review” step to verify that the output values match the source documents. For chunking strategy: split by paragraph or chapter level, keeping a single chunk under 512 tokens. For the vector database, choose open-source solutions (like Faiss or Milvus) or cloud services. For the embedding model, select mainstream options like BGE-large or text-embedding-3-small based on data scale.

    Compliance and Data Masking

    Financial scenarios must comply with local financial regulations, and model outputs should not constitute investment advice. Personal financial data must be masked. Specific methods include using regular expressions to replace ID numbers (e.g., re.sub(r'\d{17}[\dXx]', '[ID_MASKED]', text)) and replacing specific amounts with ranges (e.g., “100K~500K”). Additionally, all code execution and data transmission processes must adhere to relevant data security and privacy protection standards.

    4. Summary and Action Checklist

    Whether it is the cost-effective loop of AI code execution, the creative expansion brought by LLM-generated 3D assets, or the strict logical rigor required in financial RAG, it is clear that LLMs are evolving from “generalized conversational tools” into a “professional productivity foundation.” Enterprise developers can start implementation with these three steps:

    1. Evaluate Sandbox Solutions: Choose Docker or Firecracker sandboxes, replace the pseudocode’s dummy classes with real SDKs, and disable hardcoded keys.
    2. Select 3D Toolchain: Based on team capabilities and project scale, choose one from Blender, Maya, or Houdini to build a script generation pipeline.
    3. Build Financial RAG Pipeline: Chunk by 512 tokens, select an appropriate embedding model, and deploy numerical verification and masking modules to ensure compliance and auditability.

    Through rational architecture and cost control, developers can achieve cost reduction, efficiency gains, and business innovation in vertical scenarios.