What an AI Should Never Decide on Its Own in a PHP Application
Artificial intelligence can already write code, classify information, summarize documents, detect patterns, and make decisions based on large amounts of data.

Artificial intelligence can already write code, classify information, summarize documents, detect patterns, and make decisions based on large amounts of data.
In a PHP application, this opens up many possibilities.
We can use AI to interpret text, suggest responses, categorize support requests, detect potential fraud, analyze documents, or even help users perform certain tasks.
The problem starts when we give AI the role of the final authority in the system.
There is a big difference between asking AI to suggest an action and allowing it to decide whether that action should actually happen.
This distinction matters because AI models work with probabilities. Business applications, on the other hand, often need to work with rules, permissions, consistency, and traceability.
In this article, I will look at several types of decisions that, from a software development perspective, should not be delegated entirely to AI in a PHP application.
1. Who Can Access What
One of the decisions AI should not make on its own is:
“Is this user allowed to access this resource?”
Authorization should be based on explicit application rules.
For example:
if (!$user->hasPermission('finance.view')) {
throw new AccessDeniedHttpException();
}AI can help interpret a user’s request:
“I want to view the financial data for the Picos branch.”
But AI should not be the component deciding:
“This user probably has access to those financial records.”
Authorization should be based on verifiable information such as:
- identity;
- role;
- permissions;
- scope;
- organization;
- relationship with the resource;
- business rules.
A better pattern
AI can transform natural language into an intention.
The application decides whether that intention is allowed.
User
↓
AI interprets the request
↓
Application identifies the operation
↓
Authorization rules
↓
Execute or denyAI interprets.
The application authorizes.
2. Changing User Permissions
Allowing AI to change user permissions directly is even more dangerous.
Imagine an administrator says:
“Give John access to the finance module.”
AI could interpret who John is and what role the administrator is asking for.
But the application should explicitly validate the requested change:
$allowedRoles = [
'finance',
'finance_manager',
];
if (!in_array($requestedRole, $allowedRoles, true)) {
throw new DomainException('Invalid role.');
}Sensitive permission changes should also have:
- authentication;
- authorization;
- auditing;
- identification of the person responsible;
- traceability.
AI can prepare the change.
It should not be the authority that grants the privilege.
3. Financial Transactions
This is probably one of the clearest examples.
Imagine a system that allows users to:
- create payments;
- cancel charges;
- issue refunds;
- transfer money;
- change bank details;
- approve expenses.
AI can analyze a request such as:
“Refund the customer’s latest payment.”
But the financial operation itself should still be controlled by deterministic business rules.
For example:
if ($payment->isRefunded()) {
throw new DomainException('Payment has already been refunded.');
}
if (!$payment->canBeRefunded()) {
throw new DomainException('Payment cannot be refunded.');
}AI can identify which payment the user is referring to.
But the application should determine whether that payment is actually eligible for a refund.
4. Permanent Data Deletion
Permanent deletion is another decision that should not depend entirely on a model.
Consider a request:
“Delete this customer’s data.”
AI can identify which customer the user is talking about.
But the application still needs to validate:
- who is requesting the operation;
- whether the user has permission;
- whether the data can actually be deleted;
- whether retention requirements apply;
- whether related records exist;
- whether anonymization should be used;
- whether additional confirmation is required.
A safer workflow could look like this:
AI
↓
Identifies the customer
↓
Application validates permissions
↓
Application checks retention rules
↓
Application requests confirmation
↓
Application performs deletionAI should not simply be given a tool such as:
$tools = [
'delete_customer'
];and then be allowed to decide when to execute it.
5. Irreversible Operations
The problem is not limited to deletion.
Any operation that is difficult to undo deserves extra protection.
Examples include:
- closing an account;
- canceling a contract;
- closing a financial period;
- issuing a final document;
- permanently reducing inventory;
- publishing an official record;
- sending a mass communication;
- making a permanent data change.
A useful rule of thumb is:
The greater the impact and the harder the operation is to reverse, the less autonomy AI should have.
6. Changing Business Rules
Another mistake would be allowing AI to determine which business rules should apply.
Imagine a system where AI is asked:
“Determine the discount for each customer.”
AI might suggest a percentage.
But it should not replace explicit rules such as:
if ($customer->isPremium()) {
$discount = 10;
}with an unrestricted probabilistic decision.
We can still use AI to generate a recommendation:
{
"suggested_discount": 8,
"reason": "Customer has a strong history of recurring purchases."
}The application can then enforce its own limits:
$discount = min($suggestedDiscount, 10);In this model, AI suggests.
The application enforces.
7. Security Decisions
This may be one of the most important areas.
AI can help identify suspicious behavior, but it should not be the only mechanism responsible for critical security decisions.
For example:
- blocking an account;
- approving authentication;
- resetting a password;
- disabling MFA;
- allowing a sensitive operation;
- changing credentials;
- marking a transaction as safe.
Imagine this flow:
Login
↓
AI says "this looks like the user"
↓
Access grantedThat would be an extremely fragile security design.
The application should still rely on traditional security mechanisms such as:
- authentication;
- sessions;
- tokens;
- MFA;
- access control;
- rate limiting;
- password policies;
- logging;
- origin validation;
- explicit security rules.
AI can provide an additional analysis layer.
It should not replace the application’s security controls.
8. Validating Official Documents
A model can be very good at understanding text.
That does not make it the final authority on whether a document is valid.
For example:
“Is this document valid?”
AI may identify:
- suspicious fields;
- inconsistencies;
- missing information;
- differences between documents.
But whenever possible, the application should rely on objective validation rules.
If an official API, digital signature, certificate, or trusted verification mechanism exists, that mechanism should remain the source of truth.
AI can provide an analysis layer.
It should not become the document authority.
9. Setting Critical Values
Another area that deserves caution is allowing AI to choose values directly related to the business.
Examples include:
- product prices;
- credit limits;
- penalties;
- commissions;
- fees;
- budgets;
- maximum discounts;
- refund amounts.
AI might return something like:
{
"price": 149.90,
"confidence": 0.87
}That does not mean the application should immediately execute:
$product->setPrice($aiPrice);without validation.
The application should still enforce its own rules:
if ($aiPrice <= 0) {
throw new DomainException('Invalid price.');
}
if ($aiPrice < $minimumPrice) {
throw new DomainException('Price is below the allowed minimum.');
}AI can participate in the decision.
It does not need to be the one making the final decision.
10. Contracts and Legal Commitments
Operations that create legal commitments require additional care.
For example:
“Generate the contract and send it for signature.”
AI may help generate the document.
But the application should control:
- which contract template is used;
- which version is active;
- who is authorized;
- which data was inserted;
- which terms were accepted;
- who approved the action;
- which version was actually signed.
The issue is not whether AI can generate documents.
The issue is turning probabilistically generated content into an official commitment without proper validation.
11. Direct Database Changes
One of the practices that deserves particular attention is allowing an AI agent to execute arbitrary SQL in production.
For example:
User:
"Fix John's customer record."
AI:
UPDATE customers
SET status = 'active'
WHERE name = 'John';This kind of autonomy can create errors that are difficult to detect or reverse.
In critical systems, it is much safer to expose controlled application operations:
$customerService->activateCustomer($customerId);instead of providing unrestricted access such as:
executeSql($query);This creates an important architectural boundary.
AI should not decide how the database should be manipulated.
It should invoke explicitly allowed application operations.
12. Changing Production Configuration
AI can analyze logs and make useful recommendations.
For example:
“PHP-FPM appears to have too few workers. Consider increasing
pm.max_children.”
That can be valuable.
But allowing the model to automatically execute:
systemctl restart php8.2-fpmor modify production configuration files without restrictions is a completely different level of autonomy.
In critical environments, there is an important difference between:
AI diagnosesand:
AI changes productionThe first can be extremely useful.
The second requires additional controls.
13. Automatically Approving Deployments
AI-powered tools can analyze:
- pull requests;
- automated tests;
- logs;
- vulnerabilities;
- code changes.
That does not necessarily mean AI should be the only authority deciding:
“This change is safe to deploy to production.”
A pipeline could look like this:
Commit
↓
Automated tests
↓
Security analysis
↓
AI analysis
↓
Human review
↓
DeploymentAI can increase the capabilities of the development process.
It does not automatically eliminate the need for review.
14. Automatically Classifying Users in Critical Situations
AI-based classification also deserves careful consideration.
Examples include:
- approving credit;
- blocking an account;
- classifying fraud;
- denying access;
- assigning risk levels;
- prioritizing support requests.
Even if a model returns:
{
"fraud_probability": 0.92
}that should not automatically become:
$account->block();The system should still define:
- which signals are considered;
- which thresholds apply;
- what happens with false positives;
- whether human review is available;
- how users can challenge a decision;
- how the decision and its inputs are recorded.
15. The Principle I Use: AI Suggests, the Application Decides
A useful architecture for AI-enabled systems is to clearly separate responsibilities.
We can think in terms of three layers:
┌─────────────────────────────┐
│ AI │
│ interpretation / suggestion │
└──────────────┬──────────────┘
↓
┌─────────────────────────────┐
│ Application Rules │
│ validation / authorization │
└──────────────┬──────────────┘
↓
┌─────────────────────────────┐
│ Execution │
│ database / API / business │
└─────────────────────────────┘AI can be excellent at tasks such as:
- understanding natural language;
- summarizing;
- classifying;
- suggesting;
- detecting patterns;
- generating content;
- transforming data;
- extracting information.
The application should remain responsible for:
- authentication;
- authorization;
- validation;
- business rules;
- data integrity;
- limits;
- transactions;
- persistence;
- auditing.
This separation makes system behavior much more predictable.
A Practical PHP Example
Imagine an assistant that receives:
“Cancel order 54321.”
AI could return a structured intent:
{
"intent": "cancel_order",
"order_id": 54321
}This is much safer than allowing AI to execute the business operation directly.
The PHP application receives the intent:
$command = $ai->interpret($message);and then applies its own rules:
if ($command->intent === 'cancel_order') {
$order = $orderRepository->find($command->orderId);
if (!$order) {
throw new NotFoundException();
}
if (!$currentUser->canCancel($order)) {
throw new AccessDeniedHttpException();
}
if (!$order->canBeCancelled()) {
throw new DomainException(
'The order can no longer be cancelled.'
);
}
$orderService->cancel($order);
}There is now a clear separation of responsibilities.
AI:
“I believe the user wants to cancel order 54321.”
Application:
“I will verify whether this user is actually allowed to do that.”
That is an important architectural distinction.
Use AI as a Copilot, Not as the Authority
An application designed for AI does not need to reject automation.
The goal is not to artificially limit AI.
The goal is to put AI in the right place within the architecture.
AI can be extremely powerful for:
- interpreting requests;
- accelerating workflows;
- suggesting decisions;
- detecting anomalies;
- analyzing large amounts of data;
- helping developers;
- improving the user experience.
But certain decisions should remain protected by deterministic application rules.
Especially when they involve:
money, access, security, sensitive data, deletion, contracts, permissions, or irreversible operations.
A simple rule can help during development:
If a decision can have a significant impact and there is no easy way to undo the result, AI should not be the sole authority over that decision.
A Quick Checklist
Before allowing AI to perform an action directly in a PHP application, ask:
- Does this action involve money?
- Does it change permissions?
- Does it affect security?
- Does it delete data?
- Is it difficult to undo?
- Does it change a business rule?
- Does it involve sensitive data?
- Can it create a legal commitment?
- Can it affect multiple users?
- Is deterministic validation possible?
- Is the action audited?
- Is there a limit on what the AI can do?
- Is rollback available?
- Is human review required?
The more “yes” answers you have, the more control should exist around AI autonomy.
Conclusion
The conversation about AI in software development should not only be:
“What can AI do?”
An equally important question is:
“What should AI be allowed to do?”
In a PHP application, integrating AI does not mean giving the model complete control over the workflow.
A safer architecture is one where AI interprets, analyzes, and suggests, while the application remains responsible for validation, authorization, and execution.
In the end, we do not have to choose between automation and control.
We can have both.
AI can be the copilot.
But the application’s rules remain in command.