Evaluate a return request with an existing Function. The example returns a policy assessment; it does not authorize a return, create a shipping label or issue a refund.
Connect the permitted order through WooCommerce, Wix Stores or Squarespace Commerce. Each still needs a trusted actual delivery timestamp and merchant policy; an order creation/completion field is not a substitute.
Before you begin
- A merchant-approved return policy. The fictional example allows unused, non-final-sale items in their original packaging within 30 elapsed days of delivery; damaged items require support review. Replace these rules before use.
- An application-owned order access check and a trusted source of the delivery timestamp and final-sale flag. A fulfillment administrator or your backend must supply them. Shopify Get order’s creation time is not a delivery time.
- A request timestamp recorded by your application and the customer’s confirmed item condition and original-packaging status.
Studio
Open the test project in Agent studio.
Code
Use a Voiceflow bearer credential with access to your test project and Environment. Keep it on your backend or development machine. Set:
The API examples use the Environment’s saved Draft. Standalone execution does not attach a tool, compile an agent or publish a release.
Prepare the policy function
Download assess-return.mjs, or copy the source below. Replace the illustrative policy with your approved rules. Declare these string inputs:
Declare outputs decision and reason. Times must be UTC ISO instants; the window uses elapsed time rather than local calendar dates. Unknown or invalid inputs produce needs_review.
Studio
- Open Tools and create a Function named Assess return request.
- Paste the source and declare the five Input variables and two Output variables above.
- Save and test with the fixed example values before using it in a conversation.
Code
Use Node 22+ on your development machine. Save create-function.mjs and assess-return.mjs in the same directory. Inspect the downloaded source and apply your approved merchant settings before creating it.
The helper needs Function create/update permissions and uses the stable Function API:
- Creates the Function, then adds its input/output declarations through
function-variable/batchin the selected Environment’s Draft. - Leaves agent attachment and publication as separate steps.
- Is not idempotent: inspect the project before rerunning after a failed request.
The saved functionID is the ID produced by creation, not a name or a guessed identifier.
Return-assessment Function source
Copy the complete example and adapt its rules to the merchant’s approved policy.
Run the assessment
Populate trusted inputs
Have your backend supply the permitted order’s delivery time and final-sale status, and record the request time. Use the table’s fixed values for this controlled test.
Define and populate conversation variables before mapping them. An empty variable definition is not a verified value.
Execute the saved function
Studio
- Add the saved Function to a Workflow’s Function step and map the five verified inputs.
- Create conversation variables
return_decisionandreturn_reason. Map Function outputsdecisionandreasonto them. - Route
return_decisionexplicitly using the decisions below.
A Playbook can also call the Function; agent-generated values do not replace trusted fulfillment data.
Code
Require success: true, error: null and truncated: false, then inspect output.outputVars. Every declared input must be present as a string. This is standalone execution of the saved Draft; agent attachment and compilation are separate if your application needs the agent to invoke it.
Explain and route the decision
For the sample, expect eligible_for_review. Route the actual output:
Pass only the permitted order and assessment to support. That workflow owns creating and confirming the case.
Verify the policy boundary
Studio
Verify the actual Function outputs for each boundary:
- Exactly 30 elapsed days: an otherwise qualifying request returns
eligible_for_review. - Beyond 30 days, final-sale, used or missing original packaging: returns
outside_policyunder the example rules. - Damaged, malformed dates, request before delivery or missing data: returns
needs_review.
Check that the conversation follows the actual output. No path should promise a refund or return authorization from this assessment alone.