invoke-ai/InvokeAI · error · ValueError
Invalid regex: {e}
Error message
Invalid regex: {e} What it means
validate_url_regex is a pydantic field validator that compiles the configured URL-filter regex with re.compile(); if re.error is raised the ValueError 'Invalid regex: {e}' surfaces. This guarantees the app never stores an un-compilable regex used for URL filtering.
Source
Thrown at invokeai/app/services/config/config_default.py:62
"external_openai_api_key",
"external_openai_base_url",
"external_seedream_api_key",
"external_seedream_base_url",
)
class URLRegexTokenPair(BaseModel):
url_regex: str = Field(description="Regular expression to match against the URL")
token: str = Field(description="Token to use when the URL matches the regex")
@field_validator("url_regex")
@classmethod
def validate_url_regex(cls, v: str) -> str:
"""Validate that the value is a valid regex."""
try:
re.compile(v)
except re.error as e:
raise ValueError(f"Invalid regex: {e}")
return v
class InvokeAIAppConfig(BaseSettings):
"""Invoke's global app configuration.
Typically, you won't need to interact with this class directly. Instead, use the `get_config` function from `invokeai.app.services.config` to get a singleton config object.
Attributes:
host: IP address to bind to. Use `0.0.0.0` to serve to your local network.
port: Port to bind to.
allow_origins: Allowed CORS origins.
allow_credentials: Allow CORS credentials.
allow_methods: Methods allowed for CORS.
allow_headers: Headers allowed for CORS.
ssl_certfile: SSL certificate file for HTTPS. See https://www.uvicorn.dev/settings/#https.
ssl_keyfile: SSL key file for HTTPS. See https://www.uvicorn.dev/settings/#https.
log_tokenization: Enable logging of parsed prompt tokens.View on GitHub (pinned to 0b6a024f2f)
Solutions
- Fix the regex syntax reported in the message (e.g. close the group, escape the bracket)
- Validate the pattern quickly in Python: re.compile(your_pattern) before putting it in config
- Prefer raw strings in YAML/ENV to preserve backslashes (use single quotes in YAML)
Example fix
// before (invokeai.yaml) url_regex: '.*\.(png|jpg' # unclosed group // after url_regex: '.*\.(png|jpg)$'
Defensive patterns
Strategy: validation
Validate before calling
import re
try:
re.compile(cfg.url_regex)
except re.error as e:
raise ValueError(f"fix url_regex in config: {e}") Try / catch
try:
InvokeAIAppConfig(url_regex=pattern)
except ValueError as e:
if str(e).startswith('Invalid regex'):
print('Fix the regex in invokeai.yaml:', e) Prevention
- Test regexes with re.compile before adding to config
- Use YAML single quotes to preserve backslashes
- Avoid porting JS-specific regex syntax into Python
When it happens
Trigger: Setting the url_regex config field (env var, config file, or CLI) to a syntactically invalid regex such as 'foo(' , '[unclosed' , or '*quantifier'.
Common situations: Hand-edited invokeai.yaml with an escaping mistake (e.g. '\.' vs '.') ; quoting issues where backslashes are eaten by YAML/env parsing; porting a JavaScript regex with unsupported syntax into Python.
Related errors
- Invalid generation_devices value '{v}'. Use 'auto' or a list
- generation_devices cannot be an empty list. Use 'auto' or a
- base_url must not start with reserved path segment '/{first_
- stop must be greater than start
- cfg_scale must be greater than 1
AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29).
Data as JSON: /api/errors/b4f46aff88ffbb71.
Report an issue: GitHub.