Implement a Function to a Strict Contract

3 Views
0 Uses

Prompt

ChatGPT
Claude
Grok
OpenRouter
You are a careful senior {{LANGUAGE}} engineer. Implement exactly one function to the contract below, with production-quality error handling and nothing extra.

Function signature (name, parameters, return type): {{SIGNATURE}}
Behavior, including examples of input and expected output: {{BEHAVIOR}}
Constraints (performance limits, memory, allowed dependencies, language version, style guide): {{CONSTRAINTS}}

Requirements:
1. Validate inputs at the boundary, and fail with clear, specific errors that use the language's idiomatic mechanism.
2. Handle these edge cases explicitly: empty input, a single element, very large input, duplicates, and Unicode or locale issues where text is involved. Say how each is handled.
3. State the time and space complexity and why.
4. Add a short docstring or comment describing the contract, not the obvious mechanics.
5. Provide 6–10 example-based tests covering the examples above plus the edge cases.
6. After the code, list any assumption you made that the contract didn't settle.

Do not change the signature. Do not add logging, configuration, classes or helper modules unless the constraints require them. If the behavior examples contradict each other, point out the contradiction instead of picking one silently.

Customize this prompt

Fill in the variables below to personalize this prompt:

ChatGPT
Claude
Grok
OpenRouter

Model Settings

Recommended Models

ChatGPT Claude Gemini

Temperature

0.7

Max Tokens

2000

Additional Notes

Best for: Getting one well-specified function written correctly, not a whole module

About this prompt

“Implement a Function to a Strict Contract” is a free prompt for ChatGPT in the Coding & Software category, 182 words long, added to The Prompt Index on October 28, 2026 by The Prompt Index. Copy it with the button above, paste it into ChatGPT or any other AI chat assistant, and send it.

It has 4 placeholders to fill in first: {{LANGUAGE}}, {{SIGNATURE}}, {{BEHAVIOR}}, {{CONSTRAINTS}}. Use the “Customize this prompt” fields to personalise it before you copy.

Recommended models: ChatGPT, Claude, Gemini.

0 upvotes, sent to an AI tool 0 times, viewed 3 times.

Browse all Coding & Software prompts, the AI prompt database or use the AI prompt finder to search every prompt.