For the complete documentation index, see llms.txt. This page is also available as Markdown.

Effective prompting

Write effective prompts for Harness AI to generate pipelines, services, environments, and other resources.

Harness AI generates Harness Platform entities from natural language prompts. Clear, detailed, and specific prompts produce better results. This topic teaches you how to write effective prompts with examples of weak versus strong phrasing across pipelines, services, environments, secrets, connectors, templates, and cost perspectives.


What you will learn in this topic

By the end of this topic, you will be able to:


Before you begin

Before you write prompts for Harness AI, ensure you have the following:

  • Harness account access: Permissions to create resources (pipelines, services, environments, connectors, secrets) at the Account, Organization, or Project level. Go to RBAC in Harness for more information on roles and permissions.

  • Resource context: Names of existing connectors, repositories, branches, services, and environments you want to reference in your prompts.


Understand why prompt specificity matters

Harness AI performs best when prompts are clear, detailed, and specific. For DevOps use cases, the difference between "create a pipeline" and "create a CI/CD pipeline that builds a Docker image and deploys to Kubernetes" is the difference between vague output and production-ready pipelines.


Apply core prompting guidelines

Follow these guidelines when writing prompts for Harness AI:

  • Be specific: Name repositories, branches, connectors, services, perspectives, and deployment strategies.

  • Use action words: Start with verbs like Generate, Create, Define, Add, Extend.

  • Provide inputs: List parameters such as IMAGE_TAG, REPLICA_COUNT, or environment variables.

  • Focus on one resource: Prompts that focus on a single resource are more reliable.

  • Iterate: Begin with a broad prompt, then refine with more detail in follow-up prompts.


Write effective prompts for pipelines

Use detailed prompts to generate pipelines with build, test, scan, and deployment stages.

Weak Prompt
Strong Prompt
Why It Is Better

Create a pipeline for my app

Generate a Harness CI/CD pipeline that builds a Docker image and pushes to Dockerhub. Add a CD stage to deploy a Kubernetes service to namespace dev on cluster core-dev.

Includes build, push, and deployment targets with specific namespace and cluster.

Make a pipeline

Create a pipeline that runs unit tests for Python, builds with Dockerfile, scans image with Semgrep, and deploys to staging using a Rolling strategy. Use GitHub connector rohan-git.

Specifies language, build, scan, deploy, strategy, and connector.


Write effective prompts for services

Specify service type, name, chart path, runtime, and variables.

Weak Prompt
Strong Prompt
Why It Is Better

Make a Kubernetes service

Generate a Kubernetes service definition named portal using Helm with chart path /cd/chart/portal. Expose variables: IMAGE, TAG, REPLICA_COUNT. Include artifact references.

Includes name, chart path, exposed variables, and artifact references.

Create a Lambda service

Create a serverless (AWS Lambda) service named router with runtime nodejs18.x, artifact from runtime input, and environment variables LOG_LEVEL, STAGE.

Specifies runtime, artifact source, and environment variables.


Write effective prompts for environments

Define environment name and type explicitly.

Weak Prompt
Strong Prompt
Why It Is Better

Create an environment

Generate an Environment named staging (type: PreProduction)

Defines name and environment type explicitly.

Make prod environment

Create a Production environment named prod

Clear scope for production use.


Write effective prompts for secrets

Harness AI creates the secret object without values. You must add values manually in the UI. Secret values are never sent to AI.

Weak Prompt
Strong Prompt
Why It Is Better

Add a secret

Create a Secret Text named docker-hub-token. Store in default Secret Manager.

Includes type, name, and storage location.


Write effective prompts for connectors

Include connector type, name, repository, and credential references.

Weak Prompt
Strong Prompt
Why It Is Better

Make a Docker connector

Generate a Docker Registry connector named canary-docker pointing to harness/canary with credentials from secret refs usernameRef: canary and passwordRef: docker-hub-token.

Includes name, repository, and credential references.

Create a Vault connector

Create a HashiCorp Vault connector, called dev-vault and default the rest of the values.

Identifies type, name, and defaults.


Write effective prompts for templates

Reference stage templates or pipeline templates by name.

Weak Prompt
Strong Prompt
Why It Is Better

Use a template

Create a Pipeline with the Deploy to K8s Stage Template.

Directly references a stage template by name.

Add template

Create a Pipeline with the Golden K8s Pipeline Template.

Specifies which pipeline template to reuse.


Write effective prompts for cost perspectives

Cost perspectives group cloud spend by application, environment, service, or team. Use specific grouping criteria and organizational terms in your prompts.

Application cost perspectives

Weak Prompt
Strong Prompt
Use Case

Make a perspective for apps.

Could you create a Cost Perspective rules based on Application costs for my payment and checkout apps?

Groups spend by application, giving insights into cost per app.

Environment cost perspectives

Weak Prompt
Strong Prompt
Use Case

I want to see dev, test, prod costs.

Could you create a Cost Perspective rules based on Environment costs (dev/staging/prod), tagging by env labels in AWS?

Creates perspectives grouped by environment, helping you compare dev, staging, and production spend.

Service or component cost perspectives

Weak Prompt
Strong Prompt
Use Case

Show me service costs.

Could you create a Cost Perspective rules based on a service/component, such as API Gateway and Database, so I can track component-level spend?

Breaks down costs by key services or components for more detailed visibility.

Team or department cost perspectives

Weak Prompt
Strong Prompt
Use Case

Make a perspective for my teams.

Could you create a Cost Perspective rules based on Team/Department costs, mapping the team tag (payments, infra, analytics) to departments?

Maps spend to teams or departments, enabling cost accountability and budget tracking.

Best practices for cost perspective prompts

  • Be clear about the grouping criteria: Specify whether you want the perspective by application, service, environment, or team.

  • Use organizational terms: If you already tag resources (for example, env=dev, team=payments), include these tags in your prompts.

  • Chain prompts: Start broad and refine (for example, "Create cost perspective by team" → "Add filters for production-only workloads").

  • Review and adjust: Harness AI creates the baseline perspective, but you can refine rules to match internal tagging standards.


Use advanced techniques

Advanced prompting techniques produce consistent and high-quality results from Harness AI.

State the resource scope

Always specify whether the resource should be created at the Account, Organization, or Project level. Also identify the resource name you want to reference or use in your pipeline.

Example

For cost perspectives, specify the actual resource scope.

Include runtime inputs

Call out variables you want parameterized with <+input>.

Example

Specify deployment strategies

Explicitly mention strategies such as Rolling, Blue/Green, or Canary.

Example

Chain stages clearly

Describe the order of stages and include gating conditions.

Example

Add verification or notifications

Ask Harness AI to extend pipelines with observability or collaboration integrations.

Example

Use iterative prompting

Start with a basic resource and refine by adding details in follow-up prompts.

Example

First prompt:

Follow-up prompt:


Best practice checklist

Use this checklist when writing prompts for Harness AI:

  • Mention target platform (Kubernetes, ECS, Lambda, VM, AWS, GCP).

  • Include connector names and secret references.

  • Add environment and service details.

  • Specify deployment strategy (Rolling, Canary, Blue/Green) for DevOps use cases.

  • Use variables for flexibility (IMAGE_TAG, SERVICE_NAME).


Last updated

Was this helpful?