sgl-project/sglang · error · RuntimeError

Completion template is not a built-in template name or a…

Error message

Completion template {completion_template_arg} is not a built-in template name or a valid completion template file path.

What it means

Same pattern as the chat-template case but for --completion-template: load_completion_template accepts either a registered builtin completion template name or a file path; when the name isn't builtin and the path doesn't exist, it raises RuntimeError.

Solutions

  1. Check builtin completion template names and use one exactly
  2. Otherwise pass an absolute path to your JSON/jinja file and confirm it exists (ls)
  3. Mount the file into the container or bake it into the image

Example fix

# before
python -m sglang.launch_server --completion-template tmpl.json
# after
python -m sglang.launch_server --completion-template /app/templates/tmpl.json
Defensive patterns

Strategy: validation

Validate before calling

import os
ok = completion_template_exists(arg) or os.path.isfile(os.path.abspath(arg))
if not ok:
    raise FileNotFoundError(arg)

Type guard

def is_loadable_completion_template(arg: str) -> TypeGuard[str]:
    import os
    from sglang.srt.parser.template_manager import completion_template_exists
    return completion_template_exists(arg) or os.path.isfile(arg)

Try / catch

try:
    tm.load_completion_template(completion_template_arg)
except RuntimeError as e:
    if "Completion template" in str(e):
        sys.exit(f"bad --completion-template: {completion_template_arg}")
    raise

Prevention

When it happens

Trigger: Passing --completion-template base (not builtin) with no file named base in the working directory, or a JSON completion-template path that's mistyped or not mounted.

Common situations: Custom JSON completion template files not shipped in the Docker image, wrong relative path, or a builtin-name typo.

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/9c0a19a1513c881b. Report an issue: GitHub.

Appendix: source

Thrown at python/sglang/srt/parser/template_manager.py:230

            model_path: Path to the model
        """
        template_name = get_conv_template_by_model_path(model_path)
        if template_name is not None:
            logger.info(f"Inferred chat template from model path: {template_name}")
            self._chat_template_name = template_name

    def load_completion_template(self, completion_template_arg: str) -> None:
        """
        Load completion template for code completion.

        Args:
            completion_template_arg: Template name or file path
        """
        logger.info(f"Loading completion template: {completion_template_arg}")

        if not completion_template_exists(completion_template_arg):
            if not os.path.exists(completion_template_arg):
                raise RuntimeError(
                    f"Completion template {completion_template_arg} is not a built-in template name "
                    "or a valid completion template file path."
                )

            self._load_json_completion_template(completion_template_arg)
        else:
            self._completion_template_name = completion_template_arg

        set_completion_template(self._completion_template_name)

    def initialize_templates(
        self,
        tokenizer_manager: TokenizerManager,
        model_path: str,
        chat_template: Optional[str] = None,
        completion_template: Optional[str] = None,
    ) -> None:
        """

View on GitHub (pinned to 0132848349)