Dev.to AI πŸ€– Ai πŸ‘ 0 πŸ“– 6 min read

How I Forced AI Coding Agents to Write Accessible, Secure Code

AI coding agents are getting remarkably good at generating code. They can scaffold a React application, build a form, write an API integration, and produce a working interface in minutes. But working code and production

AI coding agents are getting remarkably good at generating code. They can scaffold a React application, build a form, write an API integration, and produce a working interface in minutes.

But working code and production-ready code are not the same thing.

I started exploring a problem that I think many engineering teams are beginning to encounter:

How do we make AI-generated code follow engineering standards consistently, rather than simply asking the AI to follow them?

My answer became "WebCraft Pro" (https://github.com/ViviBeri/webcraft-pro): an engineering toolkit that combines reusable guidance with automated guardrails.

This is not a claim that AI cannot write good code. It can. The challenge is making good engineering practices repeatable.

  1. The Problem: Fast Code Is Not Always Good Code

AI coding agents optimize for completing the task in front of them. That is useful, but it can create problems when the context gets large, the task becomes complex, or the agent is operating under time or token constraints.

Consider a few familiar examples.

Accessibility gets treated as optional

An agent might generate:

  • Clickable "div" elements instead of semantic buttons.
  • Inputs without properly associated labels.
  • Icon-only controls without accessible names.
  • Interfaces without visible keyboard focus indicators.
  • Interactive components that work with a mouse but not a keyboard.

The page may look perfectly fine in a screenshot. That does not mean it is usable by everyone.

Security shortcuts appear in implementation details

A quick implementation might insert dynamic content directly into the DOM:

element.innerHTML = userProvidedContent;

This is dangerous when the content is untrusted. It can introduce cross-site scripting vulnerabilities.

A safer approach is to use text insertion when HTML parsing is unnecessary:

element.textContent = userProvidedContent;

When rich HTML is genuinely required, use an appropriate sanitization strategy and enforce a clear trust boundary.

Div-soup replaces semantic HTML

It is easy for generated interfaces to accumulate generic containers:

Submit

It might look like a button, but it does not automatically behave like one. Keyboard interaction, focus behavior, semantics, and accessibility all become additional responsibilities.

These are not necessarily failures of model knowledge. They are failures of consistent application.

  1. The Skeptic's Point: "LLMs Already Know Best Practices"

This is a fair objection.

Modern language models have seen enormous amounts of documentation, source code, accessibility guidance, and secure coding recommendations.

They know that:

  • Buttons should generally be actual "" elements.
  • Form controls need accessible labels.
  • Untrusted content should not be inserted as raw HTML.
  • Keyboard users need visible focus indicators.
  • Semantic HTML is preferable to unnecessary generic containers.

So why build another collection of skills and rules?

Because knowing a rule and consistently following it are two different things.

A prompt can ask an agent to produce accessible code. A skill can provide detailed implementation guidance. Both help, but neither guarantees that the final code follows the requirements.

The real question is not:

"Does the model know the right thing?"

It is:

"Can the development workflow detect when the model gets it wrong?"

That is where automated enforcement becomes important.

  1. The Solution: Guidance Plus CI Enforcement

I built WebCraft Pro around a simple idea:

Use AI-readable engineering guidance to influence implementation, and use automated checks to verify the result.

WebCraft Pro currently contains 43 skills covering engineering and front-end development practices.

The skills provide reusable guidance for tasks such as implementation, accessibility, performance, security, and maintainability.

But the skills are only one part of the system.

A zero-dependency security linter

The repository includes a security pattern audit implemented without third-party runtime dependencies.

It scans relevant Markdown code examples for potentially unsafe patterns, including:

  • "eval()"
  • "new Function()"
  • "innerHTML"
  • "dangerouslySetInnerHTML"
  • "document.write()"
  • Unsafe "postMessage" patterns

The audit is designed to identify risky examples and make them visible during repository validation.

It also supports explicit handling for teaching examples, so intentionally demonstrating an unsafe pattern does not have to be confused with recommending it for production use.

The goal is not to replace a full application security assessment. It is to catch known dangerous patterns early and consistently.

Accessibility checks

Accessibility needs more than a static review of source code.

WebCraft Pro includes keyboard and focus regression tests in its CI workflow. These help verify that keyboard interaction and focus behavior remain intact as the repository changes.

It also includes an on-demand browser checker built around Playwright and axe-core. This provides a way to assess rendered pages for accessibility issues.

These checks serve different purposes:

Check| Purpose
Keyboard/focus CI tests| Automated regression checks
Playwright browser checker| Inspect rendered page behavior
axe-core| Detect supported accessibility violations
Security pattern audit| Identify risky patterns in repository examples

No single tool proves that an application is secure or fully WCAG-conformant. The point is to combine complementary checks rather than depend on one source of truth.

Why CI matters more than another prompt

Consider the difference:

Prompt-only workflow

  1. Ask the AI to write accessible code.
  2. Review the output.
  3. Hope the requirements were followed.

Guardrail-based workflow

  1. Give the AI relevant engineering guidance.
  2. Let it implement the feature.
  3. Run automated checks.
  4. Investigate failures.
  5. Fix the implementation before merging.

The second workflow does not assume that the AI will always behave correctly.

It makes correctness part of the development process.

  1. A Small Code Example: Generic Div vs. Semantic Button

Let's look at a simple example.

Imagine asking an AI agent to create a login form with a submit control.

A weaker implementation

function LoginForm() {
return (
className="submit-button"
onClick={handleSubmit}
>
β†’

);
}

Problems:

  • A "div" does not provide native button semantics.
  • It is not automatically keyboard-operable.
  • The icon has no accessible name.
  • There is no native submit behavior.
  • Focus and interaction states must be implemented manually.

A better implementation

function LoginForm() {
return (


{/* Form fields go here */}
  <button
    type="submit"
    aria-label="Submit login form"
  >
    <span aria-hidden="true">β†’</span>
  </button>
</form>

);
}

This uses a native button and gives the icon-only control an accessible name.

For a button with visible text, prefer keeping that text as its accessible name rather than adding a redundant "aria-label":


Sign in

That is one small example of the kind of implementation guidance an AI agent can use.

However, the important distinction is that a better prompt does not prove the output is correct. The resulting page still needs to be tested.

  1. What This Does Not Solve

I want to be clear about the limitations.

WebCraft Pro does not guarantee that every AI-generated application will be secure, accessible, or production-ready.

A pattern linter cannot understand every possible security vulnerability. axe-core cannot identify every accessibility problem. Automated tests cannot replace manual keyboard testing, screen-reader evaluation, threat modeling, or engineering review.

Likewise, the benchmark examples in the repository are illustrative examples, not captured outputs from a controlled comparison of AI models.

A repeatable model evaluationβ€”with the same task, test fixture, and checks applied to outputs generated with and without relevant skillsβ€”is a separate improvement tracked in the project.

I think being explicit about these boundaries is important. Engineering tools should make their guarantees clear.

  1. Try WebCraft Pro

If you work with AI coding agents, I would be interested in how you enforce engineering standards in your own workflow.

You can explore the repository here:

"WebCraft Pro on GitHub" (https://github.com/ViviBeri/webcraft-pro)

Start with the README and its quickstart onboarding instructions. You can explore the available skills, inspect the security audit, and review the accessibility-related checks.

You do not need to adopt the entire toolkit. Even taking one ideaβ€”such as running a security pattern audit or adding keyboard-focus regression testsβ€”to your own project can be useful.

  1. A Question for the Community

I am interested in how other developers are approaching this problem.

  • Do you rely on system prompts and agent skills?
  • Do you run automated security and accessibility checks against AI-generated code?
  • Have you added CI rules specifically to catch common AI coding mistakes?
  • What guardrails have actually reduced the amount of manual review your team needs?

I am building WebCraft Pro as an engineering resource, not as a claim that one toolkit solves every AI coding problem.

If you try it, feedback and practical criticism are welcome. I would especially like to hear which checks you consider essential before AI-generated code is allowed into a production branch.

The goal is simple: let AI help us move faster without lowering the engineering standards we depend on.

πŸ“° Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.