Razvoj

Stop Prompt Engineering, Start Architecting AI's Business Logic

Prestanite s prompt inženjeringom, počnite projektirati poslovnu logiku umjetne inteligencije

“Just improve the prompt” is becoming the most expensive sentence in AI product development.

Prompts matter. They shape tone, constrain output, and make a model easier to use. But a prompt is not business logic, a database transaction, an authorization policy, or a reliable workflow engine. Treating it as any of those things creates systems that look impressive in a demo and become unpredictable under real traffic.

The useful shift is simple: stop asking the model to own decisions that software can express deterministically. Start architecting AI as one component inside a backend system with clear boundaries, validated inputs, observable behavior, and safe failure modes.

The model should propose; the system should decide

Language models are excellent at interpreting unstructured text, extracting intent, generating drafts, and choosing among carefully constrained options. They are not a substitute for rules that must always hold.

Consider a support application that helps agents issue refunds. A fragile approach asks the model: “Read this conversation and decide whether to refund the customer.” That bundles interpretation, policy, authorization, and financial action into one probabilistic response.

A better design separates those responsibilities. The model can summarize the issue and return structured signals such as the order number, requested outcome, and likely reason. The backend then checks the order, refund window, payment state, customer permissions, and policy thresholds. Only the application can authorize the financial operation.

  • Use AI for classification, extraction, summarization, and drafted language.
  • Use application code for permissions, pricing, policy enforcement, and side effects.
  • Use the database as the source of truth for state and audit history.
  • Use human review when the confidence or business risk warrants it.

This is not a limitation of AI. It is good system design. The same separation has long applied to search engines, payment providers, and external APIs.

Define an interface before writing a clever prompt

The fastest route to maintainable AI features is to design the contract first. What enters the AI boundary? What exact data comes back? Which parts of that response are optional? What happens when it is malformed, incomplete, late, or confidently wrong?

Free-form prose is difficult to validate and costly to integrate. Prefer a narrow schema that your backend can parse. For example, a ticket-triage feature may request a category, urgency, and a concise summary rather than an unconstrained paragraph of analysis.

final class TicketTriage
{
    public function __construct(
        public readonly string $category,
        public readonly string $urgency,
        public readonly string $summary,
    ) {}
}

The model response still arrives from an unreliable boundary, so parsing is not enough. Validate every field against your domain. A category should be one of the categories the application supports. Urgency should map to a defined enum or workflow state. A summary should have a practical length limit before it reaches storage or another service.

$allowedCategories = ['billing', 'technical', 'account'];
$allowedUrgencies = ['low', 'normal', 'high'];

if (!in_array($payload['category'] ?? null, $allowedCategories, true)) {
    throw new InvalidArgumentException('Unsupported ticket category.');
}

if (!in_array($payload['urgency'] ?? null, $allowedUrgencies, true)) {
    throw new InvalidArgumentException('Unsupported ticket urgency.');
}

Prompt wording can guide the model toward valid values. Validation makes the system safe when guidance is ignored.

Build a workflow, not a single request

Many AI tasks become more reliable when decomposed into stages. A document-processing service, for example, might first extract candidate fields, then validate them against known records, then ask for clarification only where uncertainty remains. Each stage has a smaller prompt, a clearer input, and an independently testable outcome.

That structure also prevents accidental prompt sprawl. When one enormous prompt contains policy text, user context, prior conversation, formatting rules, examples, and operational instructions, small edits have surprising effects. Separate stable instructions from request-specific data, and keep both versioned in source control.

Persist what matters

If an AI response changes a user-visible workflow, record enough context to explain it later: the feature version, prompt version, model configuration identifier used by your integration, sanitized input reference, validated output, and final business action. Avoid storing sensitive content without a retention and access policy, but do not make production behavior impossible to investigate.

An audit record should distinguish between “the model suggested high urgency” and “the system escalated the ticket.” Those are different events, owned by different parts of the architecture.

Make retries safe and failures ordinary

External AI calls can time out, return temporary errors, or exceed rate limits. Your application should behave as though this will happen, because eventually it will.

For synchronous, low-risk assistance, a timeout and a clear fallback may be enough. A search assistant can return conventional search results when enrichment is unavailable. For longer work, queue a job and let the user see a pending state instead of holding an HTTP request open.

For side-effecting workflows, use idempotency. Give each requested action a durable identifier, store its status, and ensure a retry does not create duplicate emails, invoices, or updates. The AI call itself may be repeated; the resulting business action must not be repeated accidentally.

  • Set explicit connection and response timeouts.
  • Retry only transient failures, with bounded attempts and backoff.
  • Route exhausted jobs to a reviewable failure state.
  • Log request metadata and error classes without leaking secrets or private data.
  • Keep a deterministic fallback for essential user journeys.

Test behavior at the right level

You cannot unit-test a prompt into certainty. You can test the system around it rigorously.

Unit-test schema validation, policy decisions, authorization checks, and database transitions. Integration-test your AI adapter with recorded or simulated responses, including invalid JSON, unsupported values, missing fields, and slow responses. Maintain a small evaluation set of representative inputs whenever prompts or model settings change, then review whether the validated outputs remain useful.

The important metric is not whether the model produces elegant prose. It is whether the feature reliably advances a business workflow without creating hidden operational work.

Architecture is the real prompt

Prompt engineering is a valuable craft, but it is only one layer of the stack. The durable advantage comes from designing boundaries: where uncertainty is allowed, where deterministic rules take over, where data is persisted, and where humans retain control.

A well-architected AI feature does not need the model to be perfect. It expects ambiguity, contains it, and turns useful suggestions into safe outcomes. That is the difference between an AI demo that sounds capable and a backend system that can be trusted to do useful work on Monday morning.

Portret autora bloga

Mihajlo

Ja sam Mihajlo — programer vođen znatiželjom, disciplinom i stalnom željom da stvorim nešto smisleno. Dijelim uvide, tutorijale i besplatne usluge kako bih pomogao drugima da pojednostave svoj rad i rastu u svijetu softvera i umjetne inteligencije koji se neprestano razvija.