improving-drf-endpoints
What it does
This skill guides the AI through reviewing and fixing Django REST Framework endpoints and serializers. It is for developers who want their API documentation and generated code to be accurate.
When to use it
- βWhen you are editing a Django REST Framework serializer or viewset and want its fields typed correctly.
- βWhen generated API types show unknown or wrong values and you need to find the cause.
- βWhen you are reviewing an API change and want to check its field descriptions and schema.
Skill link
https://github.com/PostHog/posthog/blob/master/.agents/skills/improving-drf-endpoints/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agentβs skills folder.
Example of what to ask your AI
βHelp me review my Django API serializers so the generated docs and types show the right fields and descriptions.β
5 new skills a week. 1 minute to read.
How it works
It checks each field's type, help text and schema notes, because these details flow into the API documentation and the code generated from it. It then suggests fixes to the serializer code.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
Improving DRF Endpoints
Before you propose a contract test against the generated OpenAPI schema, check things already tried. Six PRs took that idea, and none merged.
Overview
Serializer fields are the source of truth for PostHog's entire type pipeline:
Django serializer β drf-spectacular β OpenAPI JSON β Orval β Zod schemas β MCP tools
Every help_text, every field type, every @extend_schema annotation flows downstream.
A missing help_text means an agent guessing at parameters.
A bare ListField() means z.unknown() in the generated Zod schema.
Getting the serializer right means every consumer β frontend types, MCP tools, API docs β gets correct types and descriptions automatically.
When to use
- Editing or reviewing any file that defines a
SerializerorViewSet - Fixing OpenAPI spec warnings or generated type issues
- Preparing an endpoint for MCP tool exposure
- Code review of API changes
Audit checklist
Triage: check the generated output first
Before diving into Python, look at the committed generated types to see what's broken. Find the generated files for the endpoint's product:
- Core API:
frontend/src/generated/core/ - Product APIs:
products/<product>/frontend/generated/
Each has two files:
api.schemas.tsβ TypeScript interfaces derived from serializers. Search for the serializer name and look forunknowntypes (bareListField/JSONField), missing JSDoc descriptions (missinghelp_text), or overly genericRecord<string, unknown>shapes.api.tsβ API client functions. Check if the endpoint's operation exists at all β if missing, the viewset method likely lacks@extend_schema.
This tells you exactly which fields and endpoints to prioritize.
Serializer fields
Work through this list for every serializer and viewset you touch.
- Every field has
help_textβ describes purpose, format, constraints, valid values - No bare
ListField()orDictField()β always specifychild=with a typed serializer or field - No bare
JSONField()β create a custom field class with@extend_schema_field(TypedSchema) SerializerMethodFieldhas@extend_schema_fieldon itsget_*methodChoiceFieldhas explicitchoices=with all valid values listed- Define choices as a class β
models.TextChoicesin a product's internal modules,LabeledStrEnumorLabeledIntEnumfromposthog/enums.pyin facade contract files (backend/facade/contracts.py,backend/facade/enums.py), which must not import Django. The OpenAPI component is named after the class either way (EarlyAccessFeature.Stage->EarlyAccessFeatureStageEnum, viaChoicesEnumNameOverridesinposthog/openapi/enum_names.py), so a class-backed enum never collides on field names likeformat,type,status,kind. PassX.choicestochoices=, and to name a labeled enum on aSerializerMethodFielduse@extend_schema_field(ChoiceField(choices=X.choices)), not a return type hint. Inlinechoices=[...]lists have no class to read, collide with existing choices, and fail CI under--fail-on-warn; an explicitENUM_NAME_OVERRIDESentry inposthog/settings/web.pyis the fallback for choice sets no class can carry (see serializer-fields.md) - Read vs write serializers are separate when input shape differs from output
- Every success response is backed by a serializer β returning raw dicts or untyped lists means no generated types downstream
See serializer-fields.md for patterns and examples.
Viewset and action annotations
- Every custom
@actionhas@extend_schemaor@validated_requestβ without it, drf-spectacular discovers zero parameters - Plain
ViewSetmethods have schema annotations βModelViewSetwithserializer_classis auto-discovered; plainViewSetis not @extend_schemais on the actual method (get,post,create,list), not on a helper or the class itself- Error responses are typed β use
OpenApiResponse(response=ErrorSerializer), notOpenApiTypes.OBJECT - List endpoints declare pagination β reset with
pagination_class=Noneon custom actions that don't paginate - Prefer
@validated_requestover manualserializer.is_valid()+@extend_schemaβ it handles both in one decorator - **ViewSets o
FAQ
Do I need to know Django to use it?
Yes. It is meant for developers who already work with Django REST Framework. It explains what to check, but you still need to understand the code.
What is the main benefit?
Clear help text and correct field types mean the generated API docs and client code describe each endpoint accurately.
Does it work with any API?
It is aimed at Django REST Framework APIs that generate their schema with drf-spectacular.
Details
Original description by the author
Use when editing, reviewing, or auditing DRF viewsets and serializers in PostHog. Triggers on files in posthog/api/, products/*/backend/api/, products/*/backend/presentation/, or any file importing rest_framework. Covers field typing, schema annotations, enum collision fixes, and OpenAPI spec quality β everything that flows downstream into generated TypeScript types and MCP tools.
repo: PostHog/posthog
Popularity
- GitHub stars
- 41k
- Ranking position
- #6815
- License
- β
- Updated
- 11/2/2026
Comments
- β¦
More skills from this repository
depot-ci
41kHelps your agent set up and run Depot CI workflows, a GitHub Actions alternative, including migrating existing workflows and reading run logs.
depot-container-builds
41kHelps your agent build Docker images on Depot's remote builders, including multi-platform images, pushing to registries, and fixing build failures.
depot-github-runners
41kHelps your agent move GitHub Actions jobs to Depot-managed runners, choosing runner sizes and labels, and troubleshooting runner setup issues.
editing-agents-md
41kHelps your agent decide whether a rule belongs in an AGENTS.md or CLAUDE.md file, and write it so it sticks without bloating the file.
Similar skills
api-connector-builder
280kHas your agent build new API connections following the existing pattern. Use when you need to add one more integration without creating a new way of doing things.
api-design
280kHelps your agent design REST APIs following best practices. It's useful for defining how APIs communicate, how errors are shown, and how to organize data.
backend-patterns
280kHelps your agent with server-side architecture patterns and database optimization. It's useful for building or reviewing code that runs on the server.