Skip to content

LLMs

How to use Electric with LLMs like ChatGPT and Claude and AI code editors like Cursor and Windsurf.

Using Electric with LLMs

LLMs are aware of Electric and can generate Electric code. However, LLMs have training data cut-off dates and may not be up-to-date with the latest APIs or capabilities of Electric. As a result, they may generate invalid code.

You can fix this using our llms.txt. This works equally well for new projects and for incremental adoption / migration of existing projects.

llms.txt

Electric provides an llms.txt at https://electric-sql.com/llms.txt. This contains instructions for LLMs, formatted in a way they can easily digest.

You can use this file in two ways:

  1. paste it into your chat window
  2. upload it as a file into your project

Example - ChatGPT

Manually download the Electric llms.txt file to your computer. Then in ChatGPT use the Attach or + button to upload the file from your computer:

This will upload the file and provide the information in it as context to the LLM. You can then prompt the LLM to use Electric.

Example - Claude

Similarly if you're using Claude you can either just upload the file:

Or, more powerfully, you can create a project and add the llms.txt file to the project context. This means that the instructions within it will be applied to all of the chat sessions you create within the project.

Prompting

Prompts are how you tell the LLM what you would like to do. You don't need any special prompts to tell the LLM to use Electric. You can just tell it directly, for example:

Generate a todo-list application using Electric

With the llms.txt as context, this will be enough to generate a fully working Electric application. For example, this is Claude's response:

The rule-of-thumb with prompting is that you need to provide all of the information to the LLM that it doesn't have in its training set (or project context). So, for example, if you want to use a specific database host like Supabase or Neon, you should say that. Or if you want to use a specific pattern for writes you should say that, e.g.:

Generate a todo-list application using Electric with the shared persistent pattern for optimistic writes, with Valtio as the client side store. Use hard deletes and UUIDs as primary keys. Make the data model Users -> Workspaces -> Lists -> Todos -> Comments. Allow todos to be assigned to users. Allow users to comment on todos.

It's also often productive to ask the LLM to write out an implementation plan and then implement in steps.

Do not implement the code yet. First take your time to consider the best implementation approach. Then carefully write out a high level implementation plan. Make sure to consider code quality, maintainability, UX and performance. Break down the implementation into steps which will yield working, testable code.

You can then review the plan, if necessary correct / fine-tune it and then tell the LLM to implement one step at a time. Ideally you can then ask the LLM to write tests so you can verify that the code works at each step along the way.

Incremental adoption

Because Electric works with your existing stack, it's great for incrementally migrating an existing app to use sync. Because it works with any standard Postgres, it's also very good for evolving LLM generated projects which have chosen Postgres (or a specific Postgres host like Supabase or Neon) as their default database and/or state transfer technology.

For these, you can provide the existing code as context, for example by adding a local code folder to Cursor or Windsurf.

Example - Windsurf

Here we've added the local clone of the electric-ai-chat demo app to Windsurf, by selecting the folder from our local filesystem.

You can then identify existing components or routes that are fetching data and tell the LLM to replace the data wiring with Electric sync. This can typically be achieved by selecting the relevant code and then prompting to revise it.

Example - Cursor

For example in Cursor, you can navigate to the file, select any relevant code and then prompt to tell the LLM how you'd like to change it:

More information

See the llms.txt website and this prompting guide for more information.

You may also be interested to read our Untangling the LLM Spaghetti and Building AI apps? You need sync posts: