Understanding python.analysis.autoFormatStrings in Pylance
June 23, 2026 · View on GitHub
Pylance is a fast and feature-rich language server extension for Python in Visual Studio Code, powered by the Pyright static type checker.
The python.analysis.autoFormatStrings setting controls whether Pylance automatically converts a regular string into a formatted string (f-string) when you start typing a placeholder inside it.
What is python.analysis.autoFormatStrings?
When this setting is enabled and you type an opening brace { inside a string literal, Pylance automatically adds an f prefix to the string, turning it into an f-string. For example, typing { inside "value: " produces f"value: {}".
This exists to remove a common friction point: it is easy to forget the f prefix when adding an interpolation placeholder, which results in the braces being treated as literal text. Automatically adding the prefix keeps your interpolation working as intended.
Type: boolean
Default: false
Scope: window (applies to the whole VS Code window)
Example
Suppose you type an opening brace { inside a plain string:
label = "value: "
With the setting enabled, Pylance adds the f prefix automatically as you type {, turning the string into an f-string:
label = f"value: {}"
With the setting disabled, the string keeps no prefix and the braces are treated as literal text rather than an interpolation placeholder.
How to Change python.analysis.autoFormatStrings
Using the Settings UI
- Open the Command Palette (
Ctrl+Shift+P/Cmd+Shift+P) and run Preferences: Open Settings (UI). - Search for
python.analysis.autoFormatStrings. - Check the box to enable it.
Using settings.json
{
"python.analysis.autoFormatStrings": true
}
When to Use It
- Enable if you frequently write f-strings and want the
fprefix added automatically as you insert placeholders. - Keep disabled if you prefer to control string prefixes manually, or if your codebase mixes many string types where automatic conversion would be unexpected.
Related Settings
python.analysis.autoSplitStrings— adds quotes and continuation characters when you split a string across lines.python.analysis.completeFunctionParens— adds parentheses to function completions.
For more information on Pylance settings and customization, refer to the Pylance Settings and Customization documentation.
This document was generated with the assistance of AI and has been reviewed by humans for accuracy and completeness.