Free 15-minute callFree 15-minute call →
艾维禾砺Vibe Coding LabIvheli · 1:1 coaching
Engineering deep dives

How to build an AI function

A prompt is read by people; a function is used by systems. Turning 'what to do' into 'what comes in, how it is processed, what comes out, how it is tested' makes it reusable.

Updated 2026-11-112 min readFree guides · 69/96

The problem with prompts

A prompt used a few times in a conversation is fine, but plugged into a process and run dozens or hundreds of times a day, problems appear:

  • The same input gives different results at different times
  • The output format varies, and programs cannot consume it
  • When something fails, you cannot tell which step failed
  • When someone else takes over, they cannot tell what the prompt is doing

Making it a function: four elements

  1. Input: fixed fields (text, files, parameters)
  2. Steps: how many processing blocks, and what each does
  3. Output: a fixed structure and format
  4. Tests: a set of repeatable cases

Write these four down and the prompt becomes a component rather than a paragraph.

How to design inputs

  • Fewer fields rather than more; every field must have a use
  • Separate long text from short parameters
  • Give defaults so missing values do not raise errors
  • State clearly what happens when there is no data

How to split the steps

  • Understand first (extract points, classify)
  • Then process (calculate, judge, generate)
  • Finally validate (format, facts, boundaries)
  • Every step can be run and checked on its own

How to define the output

  • Use a fixed structure (JSON, fixed fields)
  • Specify the value range and how empty values are written
  • When uncertain, output “unknown” instead of making things up
  • Include the basis or source in the output

How to test

  • Normal cases: typical inputs
  • Boundary cases: empty values, very long input, special characters
  • Failure cases: missing fields, contradictory data
  • Stability: run the same input three times and see whether the conclusion is consistent

The pass rate does not need to be 100% at the start, but it must be continuously observed and gradually improved.

How to use the tools

Visual platforms (tools like Palantir AIP Logic) provide:

  • An orchestration interface for inputs / blocks / outputs
  • A debugger: see the model’s reasoning and intermediate results at each step
  • A run panel: single runs and unit tests
  • Evaluation: run a test set in batches and check the pass rate

The core is not the tool but the structure of “input — steps — output — tests”.

When to make it a function

  • The same task will be repeated many times
  • It needs to be embedded in a process (auto-process a submitted form, run on a schedule)
  • Others need to be able to use and maintain it
  • Results need to be traceable and acceptable

Checklist

  • Input fields are fixed and have defaults
  • Steps are split into separately checkable blocks
  • The output format is fixed, including unknown handling
  • There are normal / boundary / failure test cases
  • The same input gives stable results across runs
  • Errors can be traced to a specific step
  • There is version history and changes can be rolled back

Reference: key points adapted from Palantir’s official documentation “AIP Logic: Getting started” and “AIP Evals”, rewritten for general tools and practical use.

Questions

What is the difference from just writing a prompt?

A prompt is a one-off conversation; a function has fixed inputs, a fixed output format, is repeatable and testable. Use functions for stable reuse and embedding in processes, prompts for ad-hoc questions.

Can I build one without a programming background?

You can build with visual tools: define inputs, drag in processing blocks, specify the output format, then validate with a test set. The core is not writing code but thinking the steps and acceptance through.

How do I know an AI function is usable?

Give it a fixed set of test cases (normal, boundary, failure) and check whether the pass rate is stable; run the same input several times to see whether the result is consistent; and check whether an error can be traced to a specific step.

Want to apply this to your own work?

Read next

Share this article

Where should your idea start?

Bring an idea or a question to a free 15-minute call. Confirm the conversation language and time when booking.

Book a free 15-minute call

Where should your idea start?

Free 15-minute call →Free guides

Book a free 15-minute call

Contact

Booking formEnterprise AI implementation & system developmentSee enterprise services (official site)
Add us on WeChat, mention Vibe Coding and tell us what you want to do
Add us on WeChat, mention Vibe Coding and tell us what you want to do