{"record":{"id":"f23b971e223f9eac","repo":"danielmiessler/Fabric","slug":"please-select-a-provider-and-model-first","errorCode":null,"errorMessage":"Please select a provider and model first.","messagePattern":"Please select a provider and model first\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"warning","filePath":"scripts/python_ui/streamlit.py","lineNumber":407,"sourceCode":"            logger.error(f\"Pattern {pattern_name} already exists\")\n            return False, \"Pattern already exists.\"\n\n        # Create pattern directory\n        os.makedirs(new_pattern_path)\n        logger.info(f\"Created pattern directory: {new_pattern_path}\")\n\n        # If content is provided, use fabric create_pattern to structure it\n        if content:\n            logger.info(\n                f\"Structuring content for pattern '{pattern_name}' using Fabric\"\n            )\n            try:\n                # Get current model and provider configuration\n                current_provider = st.session_state.config.get(\"vendor\")\n                current_model = st.session_state.config.get(\"model\")\n\n                if not current_provider or not current_model:\n                    raise ValueError(\"Please select a provider and model first.\")\n\n                # Execute fabric create_pattern with input content\n                cmd = [\"fabric\", \"--pattern\", \"create_pattern\"]\n                if current_provider and current_model:\n                    cmd.extend([\"--vendor\", current_provider, \"--model\", current_model])\n\n                logger.debug(f\"Running command: {' '.join(cmd)}\")\n                logger.debug(f\"Input content:\\n{content}\")\n\n                # Execute pattern\n                result = run(\n                    cmd, input=content, capture_output=True, text=True, check=True\n                )\n                structured_content = result.stdout.strip()\n\n                if not structured_content:\n                    raise ValueError(\"No output received from create_pattern\")\n","sourceCodeStart":389,"sourceCodeEnd":425,"githubUrl":"https://github.com/danielmiessler/Fabric/blob/338b89cfe97ab2d12ce30ce8b5449857a841366d/scripts/python_ui/streamlit.py#L389-L425","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Select a provider and model in the UI (they persist into st.session_state.config) before submitting pattern content","Persist the config to disk on change and reload it into session_state on app start so a refresh doesn't lose the selection","Show the current vendor/model in the pattern-creation form so the missing selection is visible before submit","Optionally disable the Create button until both fields are set, instead of raising"],"exampleFix":"# before\ncurrent_provider = st.session_state.config.get(\"vendor\")\ncurrent_model = st.session_state.config.get(\"model\")\nif not current_provider or not current_model:\n    raise ValueError(\"Please select a provider and model first.\")\n\n# after\ncfg = st.session_state.get(\"config\", {}) or load_config_from_disk()\nst.session_state.config = cfg\ncurrent_provider = cfg.get(\"vendor\")\ncurrent_model = cfg.get(\"model\")\nsubmit_disabled = not (current_provider and current_model)\nst.button(\"Create pattern\", disabled=submit_disabled, on_click=create_pattern_flow)\nif content and not submit_disabled:\n    ...","handlingStrategy":"validation","validationCode":"# Check before running fabric\ncfg = st.session_state.get(\"config\", {})\nif not cfg.get(\"vendor\") or not cfg.get(\"model\"):\n    st.warning(\"Select a provider and model in Settings before creating a pattern.\")\n    st.stop()","typeGuard":"from typing import Any\n\ndef has_provider_and_model(cfg: Any) -> bool:\n    return (\n        isinstance(cfg, dict)\n        and isinstance(cfg.get(\"vendor\"), str) and bool(cfg[\"vendor\"].strip())\n        and isinstance(cfg.get(\"model\"), str) and bool(cfg[\"model\"].strip())\n    )","tryCatchPattern":"try:\n    if not has_provider_and_model(st.session_state.get(\"config\")):\n        raise ValueError(\"Please select a provider and model first.\")\n    ...run create_pattern...\nexcept ValueError as e:\n    st.error(str(e))  # user-facing precondition message\nexcept CalledProcessError as e:\n    logger.error(f\"create_pattern failed: {e.stderr}\")\n    st.error(\"Fabric failed to structure the pattern; see logs.\")","preventionTips":["Persist config to disk and hydrate st.session_state on startup so refreshes don't clear selections","Disable the submit control until vendor/model are set rather than raising on submit","Display the active vendor/model inside the pattern-creation form"],"tags":["streamlit","configuration","precondition","python"],"backgroundTag":null,"analyzedSha":"338b89cfe97ab2d12ce30ce8b5449857a841366d","analyzedAt":"2026-08-15T11:38:51.759Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}