Prompts

Ask for type hints and error handling upfront, not bolted on after

A Python function generated without type hints and proper error handling in the original prompt usually gets both bolted on afterward, worse than if they had been part of the spec from the start.

Last updated Aug 15 · 12 min read

Why "add type hints" as a follow-up produces worse code than asking upfront

Requesting type hints and error handling as a second pass, after a function already exists, tends to produce hints that describe what the code happens to do rather than what it should guarantee — and error handling that catches whatever the existing code path might throw, rather than the specific failure modes worth handling deliberately. The Python prompt library bakes both into the initial spec instead.

The foundational entry, turning a function spec into typed code from the start, treats types as part of the contract, not a formatting pass applied after the logic already exists.

APIs: FastAPI endpoints and Pydantic v2 models

Building a FastAPI endpoint directly from requirements keeps validation and error responses part of the initial design rather than patched in later. Designing Pydantic v2 models from a real domain description — not just guessed field types — is the difference between a model that validates real business rules and one that only checks that a field is technically a string.

Data work: pandas cleaning, streaming, and validation pipelines

A pandas dataframe cleaning pipeline built with the actual messy-data cases in mind (nulls, mixed types, duplicates) beats one written for a clean sample. For data too large to load into memory at once, streaming large-file processing avoids the crash a naive read_csv call would eventually hit, and a data validation pipeline at ingestion catches bad data at the door rather than downstream where it is harder to trace back.

Testing: behaviour-driven and property-based

A pytest suite generated from actual function behaviour tests what the function is supposed to do, not just its current implementation quirks. Hypothesis property-based tests find edge cases a hand-written example-based test would never think to check.

Refactoring: async, dataclasses, and idiomatic review

Converting a sync codebase to async correctly — this refactor prompt — is a real behavioural change, not a mechanical find-and-replace of function keywords. An idiomaticity review catches code that works but does not read like Python a experienced developer would write, and converting a class to a dataclass removes boilerplate a hand-written __init__ often accumulates.

Diagnosis: circular imports, dependency conflicts, performance

A circular-import diagnosis finds the actual import cycle rather than a superficial workaround. Dependency conflict diagnosis does the same for version conflicts, and a performance profiling plan finds the actual bottleneck before optimising the wrong function entirely.

Production concerns: logging, config, resilience

Migrating to structured logging makes production logs actually queryable. Multi-environment settings configuration avoids the classic "works on my machine" gap between local and production config. A retry-with-backoff decorator and a resilient web scraper both handle the reality that external calls fail, rather than assuming they always succeed.

When Python code needs to become a real production system

These prompts sharpen individual pieces of code. A full production backend — with the deployment, monitoring and architecture that requires — is a bigger engineering project. That's exactly what Scult's software team builds, or book a meeting to talk through your project.

Need this built into your business?

The free tools and prompts on this site handle the small, solved problems. If what you need is bigger — custom software, built and maintained for you — that's Scult's day job.

Tools mentioned in this post

Prompts mentioned in this post

← All posts

Check your AI visibility

One URL in, a 0–100 score and the exact fixes out.

RUN THE CHECK

Browse all the tools

15 tools across six categories
13 of them never send your data anywhere

Free · No signup · No trial clock

SEE THE DIRECTORY