{"record":{"id":"bad0063a988614bf","repo":"astral-sh/uv","slug":"the-file-appears-to-be-a-toml-file-but-const","errorCode":null,"errorMessage":"The file `{}` appears to be a TOML file, but constraints must be specified in `requirements.txt` format","messagePattern":"The file `(.+?)` appears to be a TOML file, but constraints must be specified in `requirements\\.txt` format","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/uv-requirements/src/sources.rs","lineNumber":143,"sourceCode":"                    path.user_display(),\n                    file_name\n                ));\n            }\n        }\n        if path\n            .file_name()\n            .and_then(OsStr::to_str)\n            .is_some_and(is_pylock_toml)\n        {\n            return Err(anyhow::anyhow!(\n                \"The file `{}` appears to be a `pylock.toml` file, but constraints must be specified in `requirements.txt` format\",\n                path.user_display(),\n            ));\n        } else if path\n            .extension()\n            .is_some_and(|ext| ext.eq_ignore_ascii_case(\"toml\"))\n        {\n            return Err(anyhow::anyhow!(\n                \"The file `{}` appears to be a TOML file, but constraints must be specified in `requirements.txt` format\",\n                path.user_display(),\n            ));\n        }\n        Ok(Self::RequirementsTxt(path))\n    }\n\n    /// Parse a [`RequirementsSource`] from an `overrides.txt` file.\n    pub fn from_overrides_txt(path: PathBuf) -> Result<Self> {\n        if path == Path::new(\"-\") {\n            return Ok(Self::Extensionless(path));\n        }\n\n        for file_name in [\"pyproject.toml\", \"setup.py\", \"setup.cfg\"] {\n            if path.ends_with(file_name) {\n                return Err(anyhow::anyhow!(\n                    \"The file `{}` appears to be a `{}` file, but overrides must be specified in `requirements.txt` format\",\n                    path.user_display(),","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/astral-sh/uv/blob/f1a42680ff5272232d65748acf338b19778dde24/crates/uv-requirements/src/sources.rs#L125-L161","documentation":"Thrown by RequirementsSource::from_constraints_txt (crates/uv-requirements/src/sources.rs:143) when the constraints path has a .toml extension (case-insensitive) but its name is not one of the specially-handled files (pyproject.toml/setup.py/setup.cfg are caught earlier, pylock by error 40). uv only parses constraints in requirements.txt format, so any other TOML file is rejected before parsing.","triggerScenarios":"Running `uv pip install --constraints Cargo.toml`, `uv pip install --constraints deps.toml`, or `--constraints CONSTRAINTS.TOML`; any call to from_constraints_txt with a path whose extension equals toml ignoring case.","commonSituations":"Users keep dependency pins in a custom TOML file and assume uv reads arbitrary TOML; copy-pasting a `--constraint pyproject.toml` invocation from another tool's docs; configuration management tools generating .toml constraint artifacts.","solutions":["Convert the TOML to a flat requirements.txt-format file (`flask>=1.0` per line) and pass that to --constraints","If the TOML is a pyproject.toml you want to constrain by, extract the dependency lists into a .txt file (e.g. `uv export -o constraints.txt` from that project)","Check for a typo in the constraints path — the intended constraints.txt may have been misnamed"],"exampleFix":"# before\nuv pip install --constraints deps.toml flask\n# after\n# deps.txt: each line like `flask>=1.0`\nuv pip install --constraints deps.txt flask","handlingStrategy":"validation","validationCode":"fn acceptable_constraint_path(path: &Path) -> bool {\n    path == Path::new(\"-\")\n        || path\n            .extension()\n            .map(|ext| !ext.eq_ignore_ascii_case(\"toml\"))\n            .unwrap_or(true)\n}\n\nif !acceptable_constraint_path(&path) {\n    // convert to requirements.txt format before passing to uv\n}","typeGuard":null,"tryCatchPattern":"match RequirementsSource::from_constraints_txt(path) {\n    Err(err) if err.to_string().contains(\"TOML file\") => {\n        eprintln!(\"constraints must be requirements.txt format; got {path:?}\");\n        continue;\n    }\n    source => source?,\n}","preventionTips":["Keep constraints in plain .txt files with one PEP 508 requirement per line","Lint CI scripts to reject --constraints/--override arguments ending in .toml","Generate constraints via `uv export` rather than hand-edited TOML"],"tags":["uv","constraints","toml","file-format","pip-interface"],"backgroundTag":null,"analyzedSha":"f1a42680ff5272232d65748acf338b19778dde24","analyzedAt":"2026-08-16T04:51:47.599Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}