Critical severity beginner · Fix: 2-5 min

ValueError

vllm.LLM.__init__.ValueError: trust_remote_code must be True for remote code models

What this error means
vLLM raises a ValueError requiring trust_remote_code=True when loading models that execute remote code for safety reasons.

Stack trace

traceback
Traceback (most recent call last):
  File "app.py", line 10, in <module>
    llm = LLM(model="huggyllama/llama-7b", trust_remote_code=False)  # triggers error
  File "/usr/local/lib/python3.9/site-packages/vllm/llm.py", line 45, in __init__
    raise ValueError("trust_remote_code must be True for remote code models")
ValueError: trust_remote_code must be True for remote code models
QUICK FIX
Add trust_remote_code=True to your LLM initialization to allow loading remote code models safely.

Why it happens

vLLM requires explicit confirmation to trust and execute remote code when loading certain models to prevent security risks. If trust_remote_code is not set to True for such models, it raises this error to avoid running untrusted code.

Detection

Check for ValueError exceptions during LLM initialization and verify if trust_remote_code is set to True when loading remote code models.

Causes & fixes

1

Loading a remote code model without setting trust_remote_code=True

✓ Fix

Set trust_remote_code=True in the LLM constructor when initializing models that require remote code execution.

2

Using default trust_remote_code=False with a model that mandates remote code execution

✓ Fix

Explicitly pass trust_remote_code=True to override the default and allow the model to load safely.

Code: broken vs fixed

Broken - triggers the error
python
from vllm import LLM

llm = LLM(model="huggyllama/llama-7b")  # triggers ValueError about trust_remote_code
Fixed - works correctly
python
from vllm import LLM

llm = LLM(model="huggyllama/llama-7b", trust_remote_code=True)  # fixed by enabling trust_remote_code
print("Model loaded successfully")
Added trust_remote_code=True to explicitly allow loading remote code models, satisfying vLLM's security requirement.

Workaround

Catch the ValueError and prompt the user or log a clear message instructing to set trust_remote_code=True before retrying model loading.

Prevention

Always review model documentation to know if trust_remote_code=True is required and set it proactively when initializing vLLM models that execute remote code.

Python 3.9+ · vllm >=0.3.0 · tested on 0.3.x
Verified 2026-04
Verify ↗

Community Notes

No notes yetBe the first to share a version-specific fix or tip.