Instructions for generating Pythonic code: formatter-enforced PEP 8, modern type hints, docstrings, specific exceptions, logging, pytest tests and small single-purpose functions.
GEMINI.md. Downloaded files need to be placed in that repository path.## Gemini Python Code Generation
Applies to: **/*
When generating Python code:
## Style
- Follow PEP 8 and let the project's formatter and linter enforce it (for example Ruff or Black); do not hand-format against them.
- Use names that describe intent: `snake_case` for functions and variables, `PascalCase` for classes, `UPPER_SNAKE_CASE` for module constants.
## Type hints
- Annotate function parameters and return values. Use built-in generics and union syntax (`list[str]`, `dict[str, int]`, `str | None`) on Python 3.10+; `typing.List`, `Dict` and `Optional` are older forms.
- Use `collections.abc` types for parameters (`Iterable[str]`, `Mapping[str, int]`) and concrete types for return values.
## Docstrings
- Give public functions, classes and modules a docstring (PEP 257) that states what it does, its arguments, return value and the exceptions it raises, in the project's docstring style (Google, NumPy or reST).
## Exceptions
- Catch specific exceptions, never bare `except:`; re-raise with context (`raise ConfigError(...) from err`). Do not silence errors with `pass`.
- Use context managers (`with open(...)`) for files, locks and connections.
## Strings and logging
- Use f-strings for building strings. In logging calls, pass arguments to the logger instead (`logger.info("Loaded %d rows from %s", count, path)`) so formatting is skipped when the level is disabled.
- Use the `logging` module with a module-level `logger = logging.getLogger(__name__)`, not `print`, in library and service code. Never log secrets or personal data.
## Tests
- Generate pytest tests next to new functions: one test per behaviour, including edge cases and the error path; use fixtures and `pytest.mark.parametrize` for input tables.
## Design
- Give each function one responsibility; separate I/O (reading files, HTTP) from pure logic so the logic can be tested without mocks.
```python
import logging
from collections.abc import Iterable
logger = logging.getLogger(__name__)
def parse_scores(lines: Iterable[str]) -> dict[str, int]:
"""Parse "name,score" lines into a mapping.
Raises:
ValueError: If a line is malformed or a score is not an integer.
"""
scores: dict[str, int] = {}
for number, line in enumerate(lines, start=1):
name, sep, raw = line.strip().partition(",")
if not sep or not name:
raise ValueError(f"line {number}: expected 'name,score'")
try:
scores[name] = int(raw)
except ValueError as err:
raise ValueError(f"line {number}: score {raw!r} is not an integer") from err
logger.debug("Parsed %d scores", len(scores))
return scores
```
Project context for Gemini Code Assist agent mode and Gemini CLI: how to respond, what finished code includes, and how to verify changes before proposing them.
System instructions for Gemini on React 19 + TypeScript: typed function components, accessible markup with useId, error boundaries, measured performance and review checklists.
Generate configuration handling code
Gemini
language
Illustrative input and expected result. This example is a verification guide, not a recorded model run.
Content reviewed .
A developer asks Gemini for a utility that parses a CSV-like file of scores; earlier answers used print, bare except and typing.List.
Write a function that reads lines like 'alice,42' and returns a dict of name to score, plus tests.
A typed function using dict[str, int] and Iterable[str], a docstring with a Raises section, specific ValueError with line numbers chained with from, logger with lazy arguments, and pytest tests for valid input, a malformed line and a non-integer score.
Gemini CLI loads instructional context from GEMINI.md files: a global ~/.gemini/GEMINI.md, files in your workspace directories and their parents, and files discovered in subfolders as the agent works. The file name is configurable, so a project can tell Gemini CLI to read AGENTS.md instead of, or alongside, GEMINI.md. The rules in this directory are written as plain system instructions, so the same text can also be used as a system instruction in Gemini API or Google AI Studio requests.
GEMINI.mdStarting point, not a tested configuration for your repository. GEMINI.md has no file-scoping front matter; add this as a section, or place a GEMINI.md in the relevant subfolder. Review the instructions, adapt the file paths and run your project's existing checks.
## Gemini Python Code Generation
Applies to: **/*
When generating Python code:
## Style
- Follow PEP 8 and let the project's formatter and linter enforce it (for example Ruff or Black); do not hand-format against them.
- Use names that describe intent: `snake_case` for functions and variables, `PascalCase` for classes, `UPPER_SNAKE_CASE` for module constants.
## Type hints
- Annotate function parameters and return values. Use built-in generics and union syntax (`list[str]`, `dict[str, int]`, `str | None`) on Python 3.10+; `typing.List`, `Dict` and `Optional` are older forms.
- Use `collections.abc` types for parameters (`Iterable[str]`, `Mapping[str, int]`) and concrete types for return values.
## Docstrings
- Give public functions, classes and modules a docstring (PEP 257) that states what it does, its arguments, return value and the exceptions it raises, in the project's docstring style (Google, NumPy or reST).
## Exceptions
- Catch specific exceptions, never bare `except:`; re-raise with context (`raise ConfigError(...) from err`). Do not silence errors with `pass`.
- Use context managers (`with open(...)`) for files, locks and connections.
## Strings and logging
- Use f-strings for building strings. In logging calls, pass arguments to the logger instead (`logger.info("Loaded %d rows from %s", count, path)`) so formatting is skipped when the level is disabled.
- Use the `logging` module with a module-level `logger = logging.getLogger(__name__)`, not `print`, in library and service code. Never log secrets or personal data.
## Tests
- Generate pytest tests next to new functions: one test per behaviour, including edge cases and the error path; use fixtures and `pytest.mark.parametrize` for input tables.
## Design
- Give each function one responsibility; separate I/O (reading files, HTTP) from pure logic so the logic can be tested without mocks.
```python
import logging
from collections.abc import Iterable
logger = logging.getLogger(__name__)
def parse_scores(lines: Iterable[str]) -> dict[str, int]:
"""Parse "name,score" lines into a mapping.
Raises:
ValueError: If a line is malformed or a score is not an integer.
"""
scores: dict[str, int] = {}
for number, line in enumerate(lines, start=1):
name, sep, raw = line.strip().partition(",")
if not sep or not name:
raise ValueError(f"line {number}: expected 'name,score'")
try:
scores[name] = int(raw)
except ValueError as err:
raise ValueError(f"line {number}: score {raw!r} is not an integer") from err
logger.debug("Parsed %d scores", len(scores))
return scores
```
Ask for a small change to one matching file. Check the tool's loaded context or instruction view, inspect the diff for the requested convention, and run the relevant build or test. A well-formatted file does not guarantee the model follows every instruction.
The Gemini CLI documentation states that Gemini CLI was replaced by Antigravity CLI on June 18, 2026 for unpaid-tier and Google One users. Check which CLI your account uses; Antigravity rules are covered on the Antigravity page. Gemini CLI does not need a separate AGENTS.md mechanism: its context file name is configurable through context.fileName in settings.json (the docs show ["AGENTS.md", "CONTEXT.md", "GEMINI.md"]). Without that setting it looks for GEMINI.md.
Documentation checked 2026-11-05: Gemini CLI docs: GEMINI.md context filesGemini CLI docs: System prompt override
Project context for Gemini Code Assist agent mode and Gemini CLI: how to respond, what finished code includes, and how to verify changes before proposing them.
System instructions for Gemini on React 19 + TypeScript: typed function components, accessible markup with useId, error boundaries, measured performance and review checklists.
Generate configuration handling code