Create Custom Functions Using AI Prompts – A Guide for Developers & Creators

Introduction: Code Smarter, Not Harder

Whether you’re building a spreadsheet, automating repetitive tasks, or writing backend logic—custom functions are the building blocks of productivity. With AI tools like ChatGPT, Claude, or Gemini, you can now generate these functions on-demand using natural language prompts.

This blog shows you how to create, test, and reuse custom functions using simple AI-driven prompts. No matter your skill level, AI can help you code smarter and faster—without writing from scratch every time.


What Are Custom Functions?

Custom functions are user-defined code blocks designed to perform specific, reusable tasks. These functions:

  • Enhance automation
  • Simplify repetitive logic
  • Boost productivity
  • Reduce human error

They can be created across various platforms:

  • Excel / Google Sheets (Apps Script or VBA)
  • JavaScript (for web and utility functions)
  • Python (for data science, automation, and more)

With AI, you no longer need to memorize syntax or spend time searching Stack Overflow—just describe what you want.


How to Prompt for Custom Functions – Universal Template

🎯 Prompt Template:

Write a [language] function that takes [input type/structure] and returns [desired output/format]. Include [any constraints, formatting, comments, or enhancements].

🔁 Prompt Examples:

  1. Write a Python function that receives a list of integers and returns the top 3 highest values.
  2. Write a JavaScript function that validates an email address.
  3. Create an Excel formula that extracts the domain name from a list of email addresses.
  4. Generate a Google Sheets Apps Script function that counts cells starting with a specific letter.

1. Excel / Google Sheets Function Prompts

Prompt Example 1:

Create a custom Google Sheets Apps Script function that converts a column of names into proper case.

💡 AI Output:

function PROPERCASE(input) {
  return input.map(row => [row[0].toLowerCase().replace(/\b\w/g, c => c.toUpperCase())]);
}

Prompt Example 2:

Write an Excel VBA function that checks if a cell contains a valid Indian mobile number.

💡 AI Output:

Function IsValidIndianMobile(number As String) As Boolean
    IsValidIndianMobile = (number Like "[6-9]#########")
End Function

📌 Tips:

  • Use “Apps Script” for Google Sheets, “VBA” for Excel.
  • Ask for input validation, specific formatting, or error handling.
  • Request support for range inputs or entire columns.

2. JavaScript Function Prompts

Prompt Example 1:

Write a JavaScript function that removes all special characters from a string except alphanumerics and spaces.

💡 AI Output:

function cleanText(input) {
  return input.replace(/[^a-zA-Z0-9 ]/g, '');
}

Prompt Example 2:

Create a JavaScript function to debounce another function by 300ms.

💡 AI Output:

function debounce(func, delay = 300) {
  let timeout;
  return (...args) => {
    clearTimeout(timeout);
    timeout = setTimeout(() => func(...args), delay);
  };
}

📌 Tips:

  • Ask for ES6+ syntax, async/await support, or event-based usage.
  • Add UI instructions (e.g., how to use with onClick).
  • Request test cases for frontend use.

3. Python Function Prompts

Prompt Example 1:

Write a Python function that converts temperatures from Celsius to Fahrenheit.

💡 AI Output:

def celsius_to_fahrenheit(c):
    return (c * 9/5) + 32

Prompt Example 2:

Create a Python function that removes duplicate words from a string while preserving order.

💡 AI Output:

def remove_duplicate_words(text):
    seen = set()
    result = []
    for word in text.split():
        if word not in seen:
            seen.add(word)
            result.append(word)
    return ' '.join(result)

Prompt Example 3:

Write a Python function that takes a CSV file and returns the average of a specified numeric column.

💡 AI Output:

import csv

def average_column(file_path, column_name):
    with open(file_path, newline='') as csvfile:
        reader = csv.DictReader(csvfile)
        values = [float(row[column_name]) for row in reader if row[column_name]]
    return sum(values) / len(values)

📌 Tips:

  • Include requirements like: with/without libraries, readable output, or compatibility with Jupyter.
  • Ask for type hints and docstrings.

Extra Prompts to Try Across Languages

  • “Write a function to convert text into slug format (URL-friendly)”
  • “Create a reusable date formatter for YYYY-MM-DD to DD/MM/YYYY”
  • “Generate a function that returns true if a string is a palindrome”
  • “Build a number-to-words converter”
  • “Write a script that sends an email alert when a threshold is passed”

Enhancing AI Output: Prompt Add-Ons

When crafting your prompt, consider appending with:

  • “Add line-by-line comments”
  • “Optimize for speed and readability”
  • “Include sample input/output usage”
  • “Handle edge cases like empty input or null values”
  • “Make it suitable for integration with [tool/platform]”

Use Cases by Industry & Role

  • 👨‍💻 Developers – Utility functions for backend/frontend tasks
  • 🧾 Accountants & Analysts – Sheet functions for reporting
  • 🧠 Data Scientists – Data wrangling in Python
  • 👨‍🎨 No-code/low-code builders – Embedding logic in tools like Zapier, Glide, Retool
  • 📈 Marketers – Clean email lists, track campaign data, build spreadsheet templates

Conclusion: Code on Command

Creating custom functions used to be slow and syntax-heavy. With prompt engineering, you now generate working code by simply describing your need in plain language.

Build your own Prompt Function Library, improve it with real-world feedback, and pair your domain expertise with AI to work 10x faster. The more you prompt, the better you get.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top