danielmiessler/Fabric · warning · ValueError

Please select a provider and model first.

Error message

Please select a provider and model first.

What it means

Raised in the Streamlit pattern-creation flow before shelling out to `fabric --pattern create_pattern`. The app reads vendor and model from st.session_state.config; if either is unset (None/empty), it refuses to run because create_pattern needs an LLM to structure the pattern content. This is a deliberate precondition check, not a library failure.

Source

Thrown at scripts/python_ui/streamlit.py:407

            logger.error(f"Pattern {pattern_name} already exists")
            return False, "Pattern already exists."

        # Create pattern directory
        os.makedirs(new_pattern_path)
        logger.info(f"Created pattern directory: {new_pattern_path}")

        # If content is provided, use fabric create_pattern to structure it
        if content:
            logger.info(
                f"Structuring content for pattern '{pattern_name}' using Fabric"
            )
            try:
                # Get current model and provider configuration
                current_provider = st.session_state.config.get("vendor")
                current_model = st.session_state.config.get("model")

                if not current_provider or not current_model:
                    raise ValueError("Please select a provider and model first.")

                # Execute fabric create_pattern with input content
                cmd = ["fabric", "--pattern", "create_pattern"]
                if current_provider and current_model:
                    cmd.extend(["--vendor", current_provider, "--model", current_model])

                logger.debug(f"Running command: {' '.join(cmd)}")
                logger.debug(f"Input content:\n{content}")

                # Execute pattern
                result = run(
                    cmd, input=content, capture_output=True, text=True, check=True
                )
                structured_content = result.stdout.strip()

                if not structured_content:
                    raise ValueError("No output received from create_pattern")

View on GitHub (pinned to 338b89cfe9)

Solutions

  1. Select a provider and model in the UI (they persist into st.session_state.config) before submitting pattern content
  2. Persist the config to disk on change and reload it into session_state on app start so a refresh doesn't lose the selection
  3. Show the current vendor/model in the pattern-creation form so the missing selection is visible before submit
  4. Optionally disable the Create button until both fields are set, instead of raising

Example fix

# before
current_provider = st.session_state.config.get("vendor")
current_model = st.session_state.config.get("model")
if not current_provider or not current_model:
    raise ValueError("Please select a provider and model first.")

# after
cfg = st.session_state.get("config", {}) or load_config_from_disk()
st.session_state.config = cfg
current_provider = cfg.get("vendor")
current_model = cfg.get("model")
submit_disabled = not (current_provider and current_model)
st.button("Create pattern", disabled=submit_disabled, on_click=create_pattern_flow)
if content and not submit_disabled:
    ...
Defensive patterns

Strategy: validation

Validate before calling

# Check before running fabric
cfg = st.session_state.get("config", {})
if not cfg.get("vendor") or not cfg.get("model"):
    st.warning("Select a provider and model in Settings before creating a pattern.")
    st.stop()

Type guard

from typing import Any

def has_provider_and_model(cfg: Any) -> bool:
    return (
        isinstance(cfg, dict)
        and isinstance(cfg.get("vendor"), str) and bool(cfg["vendor"].strip())
        and isinstance(cfg.get("model"), str) and bool(cfg["model"].strip())
    )

Try / catch

try:
    if not has_provider_and_model(st.session_state.get("config")):
        raise ValueError("Please select a provider and model first.")
    ...run create_pattern...
except ValueError as e:
    st.error(str(e))  # user-facing precondition message
except CalledProcessError as e:
    logger.error(f"create_pattern failed: {e.stderr}")
    st.error("Fabric failed to structure the pattern; see logs.")

Prevention

When it happens

Trigger: Creating a new pattern with content before ever selecting a vendor/model in the sidebar; session state reset after a Streamlet rerun or browser refresh wiping st.session_state.config; config loaded from a file that lacks the 'vendor'/'model' keys; selected model cleared by a failed settings save.

Common situations: Fresh install with no config file yet, config saved under different key names than the reader expects, Streamlit session expiry mid-workflow, user assuming create_pattern is a local operation that needs no model.


AI-assisted analysis of danielmiessler/Fabric@338b89cfe9 (2026-08-15). Data as JSON: /api/errors/f23b971e223f9eac. Report an issue: GitHub.