OpenBB-finance/OpenBB · error · ValueError

Tag cannot be empty string

Error message

Tag cannot be empty string

What it means

Raised by the 'tags' field validator on an MCP prompt/route config model. Every entry in the 'tags' list must be a non-blank string; a tag that is empty or contains only whitespace is rejected so that tag-based filtering of MCP routes stays reliable. It surfaces as a pydantic ValidationError when the openapi_extra 'mcp_config' (or 'x-mcp') block is parsed.

Source

Thrown at openbb_platform/extensions/mcp_server/openbb_mcp_server/models/mcp_config.py:139

        """Validate prompt name if provided."""
        if v is not None:
            if not v.strip():
                raise ValueError("Prompt name cannot be empty string")
            # Check for valid identifier-like name
            if not re.match(r"^[a-zA-Z_][a-zA-Z0-9_]*$", v.strip()):
                raise ValueError(f"Prompt name '{v}' should be a valid identifier")
        return v

    @field_validator("tags")
    @classmethod
    def validate_tags(cls, v: list[str]) -> list[str]:
        """Validate tags are non-empty strings."""
        validated_tags = []
        for tag in v:
            if not isinstance(tag, str):
                raise ValueError(f"Tag must be a string, got {type(tag)}")
            if not tag.strip():
                raise ValueError("Tag cannot be empty string")
            validated_tags.append(tag.strip())
        return validated_tags


class MCPConfigModel(BaseModel):
    """Model for validating the main MCP configuration structure."""

    expose: bool | None = Field(
        default=None, description="Whether to expose this route (False = exclude)."
    )
    mcp_type: MCPType | None = Field(
        default=None, description="MCP type classification for the route."
    )
    methods: list[HTTPMethod] | None = Field(
        default=None, description="HTTP methods to include for this route."
    )
    prompts: list[PromptConfigModel] = Field(
        default_factory=list, description="Prompt configurations for this route."

View on GitHub (pinned to 3e071fcc2c)

Solutions

  1. Remove or fill in the empty/whitespace-only tag in the route's openapi_extra mcp_config.tags list
  2. Strip/filter blank strings before passing tags: [t for t in tags if t and t.strip()]
  3. If the config comes from user input, validate it with validate_mcp_config(config, strict=False) first to get a warning instead of a hard failure

Example fix

# before
openapi_extra={"mcp_config": {"tags": ["equities", ""]}}

# after
openapi_extra={"mcp_config": {"tags": ["equities"]}}
Defensive patterns

Strategy: validation

Validate before calling

tags = cfg.get("tags", [])
if any(not isinstance(t, str) or not t.strip() for t in tags):
    raise ValueError("mcp_config.tags contains a blank or non-string entry")
cfg["tags"] = [t.strip() for t in tags]

Type guard

def has_valid_tags(cfg: dict) -> bool:
    tags = cfg.get("tags", [])
    return (
        isinstance(tags, list)
        and all(isinstance(t, str) and t.strip() for t in tags)
    )

Try / catch

try:
    model = validate_mcp_config(cfg)
except ValidationError as e:
    if "Tag cannot be empty" in str(e):
        cfg["tags"] = [t.strip() for t in cfg.get("tags", []) if t.strip()]
        model = validate_mcp_config(cfg)
    else:
        raise

Prevention

When it happens

Trigger: Setting openapi_extra={"mcp_config": {"tags": [""]}} or {"tags": ["news", " "]]} on a FastAPI route, or embedding an empty tag in the MCP config dict passed to validate_mcp_config. Strict mode (default) raises; non-strict mode logs a warning and falls back to an empty config.

Common situations: YAML/JSON config files with trailing commas producing empty strings, template-generated tag lists that emit blank entries, copy-paste configs where an optional tag was deleted but its quotes left behind.

Related errors


AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14). Data as JSON: /api/errors/e7a4f1b4035d074f. Report an issue: GitHub.